Jump to content
  • Advertisement
Sign in to follow this  
vetts

OpenGL OpenGL & wxWidgets

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I already wrote several OpenGL applications with wxWidget/wxWindows wxGLCanvas and they are full 3D. Your problem should be somewhere else.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!