Jump to content
  • Advertisement
Sign in to follow this  
padam

OpenGL writing glut program in oo manner

This topic is 3646 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

hello everyone. I am using OpenGl(glut) for my semester project. Opengl is written in C but i wanted to use in oo manner via c++. Since I am a java programmer and i am not that much involved in c++. I have written this code which gives me error.Please help. #include <GL/glut.h> class HelloPolygon { public: void display(void); void init(); }; void HelloPolygon::display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glBegin(GL_POLYGON); glVertex3f(0.25,0.25,0.0); glVertex3f(0.75,0.25,0.0); glVertex3f(0.75,0.75,0.0); glVertex3f(0.25,0.75,0.0); glEnd(); glFlush(); } void HelloPolygon::init() { glClearColor(0.0,0.0,0.0,0.0); /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0); } int main(int argc,char **argv) { HelloPolygon hello; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(300,300); glutCreateWindow("hello"); hello.init(); glutDisplayFunc(hello.display); glutMainLoop(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Hi.
You must use static methods.


class HelloPolygon
{
public:
static void display(void);
static void init();
};


Take a look at this link: http://www.clockworkcoders.com/oglsl/
Download the libglsl-1.0.0 and you will have a good example of glut and OO.

Regards

Share this post


Link to post
Share on other sites
Thanks.
I made my method static and now its working.
Then Why was it giving error when my method was non-static ?

Thanks.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!