Added GLCanvas library (Win only at present).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@546 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
179
utils/glcanvas/samples/cube/cube.cpp
Normal file
179
utils/glcanvas/samples/cube/cube.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: cube.cpp
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include "wx/log.h"
|
||||
|
||||
#include "cube.h"
|
||||
|
||||
// This statement initializes the whole application and calls OnInit
|
||||
MyApp myApp;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
wxLog::SetTraceMask(wxTraceMessages);
|
||||
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame(NULL, "Cube OpenGL Demo", wxPoint(50, 50), wxSize(400, 300));
|
||||
|
||||
// Give it an icon
|
||||
#ifdef wx_msw
|
||||
frame->SetIcon(wxIcon("mondrian"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
|
||||
fileMenu->Append(wxID_EXIT, "E&xit");
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(fileMenu, "&File");
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
|
||||
|
||||
InitGL();
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void MyApp::InitGL(void)
|
||||
{
|
||||
/* set viewing projection */
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
|
||||
|
||||
/* position viewer */
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glTranslatef(0.0F, 0.0F, -2.0F);
|
||||
|
||||
/* position object */
|
||||
glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
|
||||
glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// My frame constructor
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style):
|
||||
wxFrame(frame, -1, title, pos, size, style)
|
||||
{
|
||||
m_canvas = NULL;
|
||||
}
|
||||
|
||||
// Intercept menu commands
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool MyFrame::OnClose(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
EVT_SIZE(TestGLCanvas::OnSize)
|
||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
|
||||
wxGLCanvas(parent, id, pos, size, style, name)
|
||||
{
|
||||
}
|
||||
|
||||
TestGLCanvas::~TestGLCanvas(void)
|
||||
{
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnPaint( wxPaintEvent& event )
|
||||
{
|
||||
if ( !GetContext() )
|
||||
return;
|
||||
|
||||
SetCurrent();
|
||||
|
||||
/* clear color and depth buffers */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/* draw six faces of a cube */
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f( 0.0F, 0.0F, 1.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
|
||||
glVertex3f(-0.5F,-0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 0.0F, 0.0F,-1.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
|
||||
glVertex3f( 0.5F, 0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
|
||||
|
||||
glNormal3f( 0.0F, 1.0F, 0.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
|
||||
glVertex3f(-0.5F, 0.5F,-0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 0.0F,-1.0F, 0.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
|
||||
glVertex3f( 0.5F,-0.5F, 0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 1.0F, 0.0F, 0.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
|
||||
glVertex3f( 0.5F,-0.5F,-0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
|
||||
|
||||
glNormal3f(-1.0F, 0.0F, 0.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
|
||||
glVertex3f(-0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
|
||||
glEnd();
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
int width, height;
|
||||
GetClientSize(& width, & height);
|
||||
|
||||
if ( GetContext() )
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
|
||||
{
|
||||
// Do nothing, to avoid flashing.
|
||||
}
|
||||
|
56
utils/glcanvas/samples/cube/cube.h
Normal file
56
utils/glcanvas/samples/cube/cube.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: cube.h
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_CUBE_H_
|
||||
#define _WX_CUBE_H_
|
||||
|
||||
#include "glcanvas.h"
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit(void);
|
||||
void InitGL(void);
|
||||
};
|
||||
|
||||
// Define a new frame type
|
||||
class TestGLCanvas;
|
||||
class MyFrame: public wxFrame
|
||||
{ public:
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
long style = wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
void OnExit(wxCommandEvent& event);
|
||||
|
||||
bool OnClose(void);
|
||||
|
||||
TestGLCanvas* m_canvas;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class TestGLCanvas: public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "TestGLCanvas");
|
||||
~TestGLCanvas(void);
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnEraseBackground(wxEraseEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#endif
|
||||
|
3
utils/glcanvas/samples/cube/cube.rc
Normal file
3
utils/glcanvas/samples/cube/cube.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
37
utils/glcanvas/samples/cube/makefile.g95
Normal file
37
utils/glcanvas/samples/cube/makefile.g95
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1993
|
||||
# Updated:
|
||||
# Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for cube example (UNIX).
|
||||
|
||||
WXDIR = ../..
|
||||
|
||||
# All common UNIX compiler flags and options are now in
|
||||
# this central makefile.
|
||||
include $(WXDIR)/src/makeg95.env
|
||||
|
||||
OBJECTS = $(OBJDIR)/cube.$(OBJSUFF)
|
||||
|
||||
all: $(OBJDIR) cube$(GUISUFFIX)$(EXESUFF)
|
||||
|
||||
wx:
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
cube$(GUISUFFIX)$(EXESUFF): $(OBJDIR)/cube.$(OBJSUFF) cube.res $(WXLIB)
|
||||
$(CC) $(LDFLAGS) -o cube$(GUISUFFIX)$(EXESUFF) $(OBJDIR)/cube.$(OBJSUFF) $(LDLIBS)
|
||||
$(RSRC) cube.$(RESSUFF) cube.exe
|
||||
|
||||
$(OBJDIR)/cube.$(OBJSUFF): cube.$(SRCSUFF)
|
||||
$(CC) -c $(CPPFLAGS) -o $@ cube.$(SRCSUFF)
|
||||
|
||||
cube.res: cube.rc
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) cube$(GUISUFFIX).exe core *.rsc *.res
|
66
utils/glcanvas/samples/cube/makefile.nt
Normal file
66
utils/glcanvas/samples/cube/makefile.nt
Normal file
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# File: makefile.nt
|
||||
# Author: Julian Smart
|
||||
# Created: 1997
|
||||
# Updated:
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds cube example (MS VC++).
|
||||
# Use FINAL=1 argument to nmake to build final version with no debugging
|
||||
# info
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
WXUSINGDLL=0
|
||||
|
||||
EXTRAINC=-I..\..\win
|
||||
EXTRALIBS=$(WXDIR)\lib\glcanvas.lib glu.lib opengl.lib
|
||||
|
||||
!include $(WXDIR)\src\ntwxwin.mak
|
||||
|
||||
THISDIR = $(WXDIR)\utils\glcanvas\samples\cube
|
||||
PROGRAM=cube
|
||||
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
$(PROGRAM): $(PROGRAM).exe
|
||||
|
||||
all: wx $(PROGRAM).exe
|
||||
|
||||
wx:
|
||||
cd $(WXDIR)\src\msw
|
||||
nmake -f makefile.nt FINAL=$(FINAL)
|
||||
cd $(THISDIR)
|
||||
|
||||
wxclean:
|
||||
cd $(WXDIR)\src\msw
|
||||
nmake -f makefile.nt clean
|
||||
cd $(THISDIR)
|
||||
|
||||
$(PROGRAM).exe: $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(PROGRAM).res
|
||||
$(link) @<<
|
||||
-out:$(PROGRAM).exe
|
||||
$(LINKFLAGS)
|
||||
$(DUMMYOBJ) $(OBJECTS) $(PROGRAM).res
|
||||
$(LIBS)
|
||||
<<
|
||||
|
||||
|
||||
$(PROGRAM).obj: $(PROGRAM).$(SRCSUFF) $(PROGRAM).h $(DUMMYOBJ)
|
||||
$(cc) @<<
|
||||
$(CPPFLAGS2) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
$(PROGRAM).res : $(PROGRAM).rc $(WXDIR)\include\wx\msw\wx.rc
|
||||
$(rc) -r /i$(WXDIR)\include -fo$@ $(PROGRAM).rc
|
||||
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.res
|
||||
-erase *.map
|
||||
-erase *.sbr
|
||||
-erase *.pdb
|
BIN
utils/glcanvas/samples/cube/mondrian.ico
Normal file
BIN
utils/glcanvas/samples/cube/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
Reference in New Issue
Block a user