writing glut program in oo manner
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;
}
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
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
Required Reading.
There is a way to do this by associating some data with your window I believe, but I can't remember the details. Someone's mentioned it on this forum before though.
There is a way to do this by associating some data with your window I believe, but I can't remember the details. Someone's mentioned it on this forum before though.
Thanks.
I made my method static and now its working.
Then Why was it giving error when my method was non-static ?
Thanks.
I made my method static and now its working.
Then Why was it giving error when my method was non-static ?
Thanks.
Quote:Original post by padamStill Required Reading.
Thanks.
I made my method static and now its working.
Then Why was it giving error when my method was non-static ?
Thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement