basic openGL code

Started by
4 comments, last by NineYearCycle 14 years, 1 month ago
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'|
Advertisement
You need to include glut.h
It looks like you forgot to include the GLUT header.
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
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.
Two things
1) have you downloaded GLUT? GLUT
2) have you placed it in the correct directory? (hint: it should be the same as the file "gl/gl.h")

You can also look into some other windowing toolkit that are newer and probably better supported. They can be found here: Window Toolkits

Andy

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

This topic is closed to new replies.

Advertisement