OpenGL & wxWidgets

Started by
6 comments, last by vetts 19 years ago
I am thinking about using wxWidgets for an openGL app and have partially gotten a small app working partially. I can't seem to get my glMatrixModes and consequently, my glTranslate won't work... the default wxCanvas also appears limited to 2d. My question is simple. Is there something I am missing, since the wx docs say that openGL integration should be seemless? Are there certain parameters I need to set up? I used glOrtho and it sort of worked to set up the viewport, but when I tried to use GL_MODELVIEW as the matrix mode and do a translation it didn't work. I'm just looking for any direction on how to get say even a simple openGL window from here working in wxWidgets. The one I was using as a test was Lesson 3, and I have to drastically change the code, just to get the 2 shapes to appear simultaneously. Any help would be appreciated.
Advertisement
please post some codes :P
Sure. glTranslate doesn't work, and there seems to be default cutting planes at -1 and 1 in every direction.

#include "wx/wx.h" #include "wx/glcanvas.h" #ifndef WIN32 #include <unistd.h> #endif class MyApp: public wxApp {   virtual bool OnInit(); }; int attrib[2]; IMPLEMENT_APP(MyApp) bool MyApp::OnInit() {         attrib[0] = WX_GL_DEPTH_SIZE;         attrib[1] = 32;   wxFrame *frame = new wxFrame((wxFrame *)NULL, -1,  "Hello GL World", wxPoint(50,50), wxSize(450,450) );   wxGLCanvas * MyGLCanvas = new wxGLCanvas(frame, -1, wxPoint(0,0), wxSize(400,400), wxSUNKEN_BORDER, _("some text"));   frame->Show(TRUE);   MyGLCanvas->SetCurrent();   //sleep(1);   //..or try this instead   glClearColor(0.0, 0.0, 0.0, 0.0);   glClear(GL_COLOR_BUFFER_BIT);   glViewport(50, 50, (GLint)100, (GLint)100);   glLoadIdentity();   glTranslatef(0.0f,1.0f,0.0f);   glColor3f(1.0, 1.0, 1.0);   glBegin(GL_TRIANGLES);         glColor3f(1.0f,0.0f,0.0f);                        // Set The Color To Red         glVertex3f( 0.0f, 1.0f, 0.0f);                        // Move Up One Unit From Center (Top Point)         glColor3f(0.0f,1.0f,0.0f);                        // Set The Color To Green         glVertex3f(-1.0f,-1.0f, 0.0f);                        // Left And Down One Unit (Bottom Left)     glColor3f(0.0f,0.0f,1.0f);                        // Set The Color To Blue         glVertex3f( 1.0f,-1.0f, 0.0f);                        // Right And Down One Unit (Bottom Right)   glEnd();                                                // Done Drawing A Triangle //  glTranslatef(1.5f,0.0f,0.0f);                                // From Right Point Move 3 Units Right   /*  glBegin(GL_QUADS);                 glVertex3f(-1.0f, 1.0f, 0.0f);                        // Left And Up 1 Unit (Top Left)                 glVertex3f( 1.0f, 1.0f, 0.0f);                        // Right And Up 1 Unit (Top Right)                 glVertex3f( 1.0f,-1.0f, 0.0f);                        // Right And Down One Unit (Bottom Right)                 glVertex3f(-1.0f,-1.0f, 0.0f);                        // Left And Down One Unit (Bottom Left)   glEnd();*/   glFlush();   MyGLCanvas->SwapBuffers();   return TRUE; }  
Just to clarify, the question isn't about the code, it's about how wxWidgets implements openGL and if there are any limitations on that implementation that would cause certain openGL functionality to work, such as only being confined to 2d instead od 3d for example.
I already wrote several OpenGL applications with wxWidget/wxWindows wxGLCanvas and they are full 3D. Your problem should be somewhere else.
Not sure if this is what you need and can't help you with wxWindows....

But if you want your interface implemented within OpenGL, check out http://glgooey.sourceforge.net/. This way your menu, buttons, listboxes, etc. are implemented natively within OpenGL rendering commands...

ok, so there are no limitations in wxWidgets? can I still use all of the openGL functions on the GlCanvas? maybe I'm just not setting the glCanvas up correctly in wxWidgets. I have some modified code that I tried, but I seem to have severe limitations on the functionality still. Thanx for the quick replies tho:-)
#include "wx/wx.h"#include "wx/glcanvas.h"/*#ifndef WIN32#include <unistd.h>#endif*/class MyApp: public wxApp{  virtual bool OnInit();};int attrib[2];IMPLEMENT_APP(MyApp)bool MyApp::OnInit(){	attrib[0] = WX_GL_DEPTH_SIZE;	attrib[1] = 32;  wxFrame *frame = new wxFrame((wxFrame *)NULL, -1,  "Hello GL World", wxPoint(50,50), wxSize(400,400) );  wxGLCanvas * MyGLCanvas = new wxGLCanvas(frame, -1, wxPoint(0,0), wxSize(400,400), wxSUNKEN_BORDER, _("some text"));  frame->Show(TRUE);  MyGLCanvas->SetCurrent();  //sleep(1);  //..or try this instead  glOrtho(-100.0,100.0,-100.0,100.0,0,100);  //glFrustum(-100.0,100.0,-100.0,100.0,0,100);  glClearColor(0.0, 0.0, 0.0, 0.0);  glClear(GL_COLOR_BUFFER_BIT);  glViewport(100, 100, (GLint)50, (GLint)50);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();//  glTranslatef(10.0f,0.0f,0.0f);/*  glBegin(GL_TRIANGLES);	glColor3f(1.0f,0.0f,0.0f);			// Set The Color To Red	glVertex3f( -20.0f, 10.0f, 0.0f);			// Move Up One Unit From Center (Top Point)	glColor3f(0.0f,1.0f,0.0f);			// Set The Color To Green	glVertex3f(-30.0f,-10.0f, 0.0f);			// Left And Down One Unit (Bottom Left)    glColor3f(0.0f,0.0f,1.0f);			// Set The Color To Blue	glVertex3f( -10.0f,-10.0f, 0.0f);			// Right And Down One Unit (Bottom Right)  glEnd();						// Done Drawing A Triangle*/ // glTranslatef(15.0f,0.0f,0.0f);				// From Right Point Move 3 Units Right   glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS);		glVertex3f(-10.0f, 10.0f, 0.0f);			// Left And Up 1 Unit (Top Left)		glVertex3f( 10.0f, 10.0f, 0.0f);			// Right And Up 1 Unit (Top Right)		glVertex3f( 10.0f,-10.0f, 0.0f);			// Right And Down One Unit (Bottom Right)		glVertex3f(-10.0f,-10.0f, 0.0f);			// Left And Down One Unit (Bottom Left)  glEnd();  glFlush();  MyGLCanvas->SwapBuffers();  return TRUE;}


I'm just trying to get a simple example working so that I can get my head wrapped around how the implementation works. I've done it with QT, so I assumed it would be similar.
Quote:Original post by AzCoder
Not sure if this is what you need and can't help you with wxWindows....

But if you want your interface implemented within OpenGL, check out http://glgooey.sourceforge.net/. This way your menu, buttons, listboxes, etc. are implemented natively within OpenGL rendering commands...


I need to be able to do a commercial project, which is why I'm trying to use wxwidgets as it's much cheaper than QT:-) If I can't get wxWidgets working... I'm sure it will work, I'm just not doing something right... Then I will look at GLGooey... thanx:)

This topic is closed to new replies.

Advertisement