e306597309
MM_... -> wxMM_... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1615 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
188 lines
4.5 KiB
C++
188 lines
4.5 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// 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"
|
|
|
|
// `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));
|
|
|
|
// Show the frame
|
|
frame->Show(TRUE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
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();
|
|
}
|
|
|
|
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)
|
|
{
|
|
m_init = FALSE;
|
|
}
|
|
|
|
TestGLCanvas::~TestGLCanvas(void)
|
|
{
|
|
}
|
|
|
|
void TestGLCanvas::OnPaint( wxPaintEvent& event )
|
|
{
|
|
// This is a dummy, to avoid an endless succession of paint messages.
|
|
// OnPaint handlers must always create a wxPaintDC.
|
|
wxPaintDC dc(this);
|
|
|
|
#ifndef __WXMOTIF__
|
|
if (!GetContext()) return;
|
|
#endif
|
|
|
|
SetCurrent();
|
|
|
|
/* init OpenGL once, but after SetCurrent */
|
|
if (!m_init)
|
|
{
|
|
InitGL();
|
|
m_init = TRUE;
|
|
}
|
|
|
|
/* 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);
|
|
|
|
#ifndef __WXMOTIF__
|
|
if (GetContext())
|
|
#endif
|
|
{
|
|
SetCurrent();
|
|
glViewport(0, 0, width, height);
|
|
}
|
|
}
|
|
|
|
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
|
|
{
|
|
// Do nothing, to avoid flashing.
|
|
}
|
|
|
|
void TestGLCanvas::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);
|
|
}
|
|
|