Sign in to follow this  
sandblasted

basic openGL code

Recommended Posts

sandblasted    100
hi guys, I'm totally new to openGL coding...by reading the redbook O tried to compile the following code using codeblocks IDE but couldnt compile...I have added the errors which are shown... can sm1 please explain the errors and provide the necessary remedy...HELP..... :( #include <windows.h> #include <gl/gl.h> void display (void) { //glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); //glOrtho(0.0,1.0,0.0,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 init (void){ glClearColor(0.0,0.0,0.0,0.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0); } int main(int argc, char** argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc (display); glutMainLoop (); return 0; } errors : D:\practice\opengl\main.c|33|warning: implicit declaration of function `glutInit'| D:\practice\opengl\main.c|34|warning: implicit declaration of function `glutInitDisplayMode'| D:\practice\opengl\main.c|34|error: `GLUT_SINGLE' undeclared (first use in this function)| D:\practice\opengl\main.c|34|error: `GLUT_SINGLE' undeclared (first use in this function)| D:\practice\opengl\main.c|34|error: (Each undeclared identifier is reported only once| D:\practice\opengl\main.c|34|error: for each function it appears in.)| D:\practice\opengl\main.c|34|error: `GLUT_RGB' undeclared (first use in this function)| D:\practice\opengl\main.c|35|warning: implicit declaration of function `glutInitWindowSize'| D:\practice\opengl\main.c|36|warning: implicit declaration of function `glutInitWindowPosition'| D:\practice\opengl\main.c|37|warning: implicit declaration of function `glutCreateWindow'| D:\practice\opengl\main.c|39|warning: implicit declaration of function `glutDisplayFunc'| D:\practice\opengl\main.c|40|warning: implicit declaration of function `glutMainLoop'|

Share this post


Link to post
Share on other sites
sandblasted    100
Quote:
Original post by sandblasted
hi guys,
I'm totally new to openGL coding...by reading the redbook O tried to compile the following code using codeblocks IDE but couldnt compile...I have added the errors which are shown... can sm1 please explain the errors and provide the necessary remedy...HELP..... :(

#include <windows.h>
#include <gl/gl.h>



void display (void) {

//glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 1.0);
//glOrtho(0.0,1.0,0.0,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 init (void){
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);

}

int main(int argc, char** argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc (display);
glutMainLoop ();
return 0;
}

errors :

D:\practice\opengl\main.c|33|warning: implicit declaration of function `glutInit'|
D:\practice\opengl\main.c|34|warning: implicit declaration of function `glutInitDisplayMode'|
D:\practice\opengl\main.c|34|error: `GLUT_SINGLE' undeclared (first use in this function)|
D:\practice\opengl\main.c|34|error: `GLUT_SINGLE' undeclared (first use in this function)|
D:\practice\opengl\main.c|34|error: (Each undeclared identifier is reported only once|
D:\practice\opengl\main.c|34|error: for each function it appears in.)|
D:\practice\opengl\main.c|34|error: `GLUT_RGB' undeclared (first use in this function)|
D:\practice\opengl\main.c|35|warning: implicit declaration of function `glutInitWindowSize'|
D:\practice\opengl\main.c|36|warning: implicit declaration of function `glutInitWindowPosition'|
D:\practice\opengl\main.c|37|warning: implicit declaration of function `glutCreateWindow'|
D:\practice\opengl\main.c|39|warning: implicit declaration of function `glutDisplayFunc'|
D:\practice\opengl\main.c|40|warning: implicit declaration of function `glutMainLoop'|




I added glut.h but still it doesnt work
the following error shows up :
D:\practice\opengl\main.c|2|glut.h: No such file or directory|

I have already addeed glu32,opengl32 and gdi 32 in the linker settings in the build option of codeblockss

Share this post


Link to post
Share on other sites
rip-off    10976
How did you include it? gl/glut.h or just glut.h?

You should be able to locate the glut.h file on your filesystem too.

Quote:

I have already addeed glu32,opengl32 and gdi 32 in the linker settings in the build option of codeblockss

Linking is a separate stage to compilation. Linker settings will not affect compile errors.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this