PDA

View Full Version : Errors with header files in OpenGL using Visual C++



wile_spice
06-21-2006, 01:32 PM
Hi, my name is Danny and I am very new to Visual C++ and OpenGL. I began using NeHe's tutorials and everything was going great. Later, I wanted to try some clipping so I transfered this code from OpenGL Programming Guide (the red book, pg 107):

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "aux.h"

void display(void)
{
GLdouble eqn[4] = {0.0,1.0,0.0,0.0};
GLdouble eqn2[4] = {1.0,0.0,0.0,0.0};

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(0.0,0.0,-0.5);

glClipPlane(GL_CLIP_PLANE0, eqn);
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE1, eqn2);
glEnable(GL_CLIP_PLANE1);

glRotate(9.0,1.0,0.0,0.0);
auxWireSphere(1.0);
glPopMatrix();
glFlush();

}


void myinit(void);
{
glShadeModel(GL_FLAT);
}


void myReshape(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w /(GLfloat) h, 1.0,20.0);
glMatrixMode(GL_MODELVIEW);

}

int main(int argc, char** argv);
{
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
auxInitPosition(0,0,500,500);
auxInitWondow(argv[0]);
myinit();
auxReshapeFunc(myReshape);
auxMainLoop(display)

}


this is the first time I encountered these errors. This is just a few of the errors I recieved:

c:\program files\microsoft visual studio\vc98\include\gl\glu.h(384) : error C2165: 'left-side modifier' : cannot modify pointers to data
c:\program files\microsoft visual studio\vc98\include\gl\glu.h(384) : error C2071: 'GLUnurbsErrorProc' : illegal storage class
c:\program files\microsoft visual studio\vc98\include\gl\glu.h(561) : error C2061: syntax error : identifier 'GLenum'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(535) : error C2146: syntax error : missing ')' before identifier 'layer'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(535) : warning C4229: anachronism used : modifiers on data are ignored
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(535) : error C2182: 'glutUseLayer' : illegal use of type 'void'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(535) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(600) : error C2061: syntax error : identifier 'GLfloat'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(601) : error C2143: syntax error : missing ';' before '__stdcall'
c:\program files\microsoft visual studio\vc98\include\gl\glut.h(605) : error C2146: syntax error : missing ')' before identifier 'type'


After trying to resolve these problems and making sure I linked the appropriate libraries(OpenGL32.lib GLu32.lib GLaux.lib), I placed the above code in a newly downloaded NeHe tutorial and I got the same errors. Now everything I compile in Visual C++ is incurring the same errors, whether they are simple programs I wrote or tutorials I downloaded!!

I would greatly appreciate some assistance regarding this issue, thanks and have a great day!!

Danny

Relic
06-22-2006, 12:56 AM
Hardly an advanced question. You should have used the beginner's forum.

Is this the whole program code?
If yes, something is severly broken with your project.
It lists GLUT errors but you use the AUX library and have no glut.h included at all.
And if you have a glut.h somewhere it might be old or corrupted.
The aux library is out of date anyway, you should move to GLUT.
http://www.opengl.org/resources/libraries/glut/

There is at least one error in your code which should not compile:
glRotate() doesn't exist, it's either glRotatef() or glRotated()

Looks like your sphere will be clipped by the zNear plane, try glTranslatef(0.0f, 0.0f, -5.0f) instead of -0.5.

Mind, the user clipping planes are transformed by the current modelview matrix, so that glTranslatef() affects them where you put it.

gluPerspective() takes doubles.

wile_spice
06-22-2006, 09:11 AM
Thanks alot!! Yea I guessed that, but I haven't been having much luck solving the errors so I decided that more advanced users would provide better help.
Yes this is the entire code, I added the glut files to the VC++ folders per the ReadMe file. I tried adding the glut header file but it didn't make a difference. I don't know how to modify the code enough to take out the aux references, could you tell me of a website that may help me with that? I was told to add a return 0 or return TRUE, this didn't help. I change what you suggested but the amount of errors didn't decrease. Thanks for your advice!!! :) When you say that gluPerspective() takes doubles do you mean that I should've written gluPerspective4d(),still no changes. This is the modified code:


// trying to use the clipping plane
#include <windows.h>
#include <gl\gl.h> // Header file for the OpenGL32 library
#include <gl\glu.h> // Header file for the GLu32 library
#include <gl\glut.h>
#include "aux.h" // Header file for the auxillary library

void display(void)
{
GLdouble eqn[4] = {0.0,1.0,0.0,0.0}; // this arguement points to the 4 coefficients of the plane equation
GLdouble eqn2[4] = {1.0,0.0,0.0,0.0}; // same as above

glClear(GL_COLOR_BUFFER_BIT); // clears color buffer

glColor3f(1.0f,1.0f,1.0f); // sets color to white
glPushMatrix(); // this pushes the current matrix stack down by one, duplicating the current matrix
glTranslatef(0.0f,0.0f,-5.0f); // this moves the current view matrix 5 units deeper into the screen

glClipPlane(GL_CLIP_PLANE0, eqn); // indicates the clipping plane
glEnable(GL_CLIP_PLANE0); // enables clip plane0
glClipPlane(GL_CLIP_PLANE1, eqn2); // indicates the clipping plane
glEnable(GL_CLIP_PLANE1); // enables clip plane1

glRotatef(90.0f,1.0f,0.0f,0.0f); // rotates object 90 degrees on the X axis (ie it moves up and down away from the viewer)
auxWireSphere(1.0); // draws a wire sphere with a diameter of 1?
glPopMatrix(); // pops the current matrix stack, replace the current matrix with the one below it on the stack
glFlush(); // empties all the buffers causing all issued commands to execute in finite time (as quickly as they're accepted by the actual rendering engine)

}
// closes the display(void) function

void myinit(void)
{
glShadeModel(GL_FLAT); // this selects which type of shading is used (Flat shading selects the computed color of one vertex and assigns it to the entire object)

}


void myReshape(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h); // specifies the affine transformation of x and y(0,0) from normalized device co ords to windows co ords
glMatrixMode(GL_PROJECTION); // specifies which matrix is the current matrix ie the Projection matrix stack
glLoadIdentity(); // replaces the current matrix with the identity matrix
gluPerspective4d(60.0, (GLfloat) w /(GLfloat) h, 1.0,20.0); // sets up a perspective projection matrix
glMatrixMode(GL_MODELVIEW); // specifies which matrix is the current matrix ie the Modelview matrix stack

}

int main(int argc, char** argv)
{
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); // tells auxInitWindow to create a RGBA and a single buffered window
auxInitPosition(0,0,500,500); // tells auxInitWindow where to position a window on the screen
auxInitWondow(argv[0]); // opens a window with the characteristics specificied by the two previous commands, the string argv appears in the title window)
myinit(); // calls the myinit() function above
auxReshapeFunc(myReshape); // specifies the function that is called when the window is resized( in this case the myReshape() function), moved or exposed. the arguement is a pointer to a function that expects 2 parameters
auxMainLoop(display); // specifies the function that's called when the window needs to be updated. This function should redraw the objects on the screen

return TRUE;
}

Relic
06-22-2006, 10:22 AM
Sorry, you misunderstood.
What I wanted to say is, wipe aux calls and headers from your project, download the GLUT library from where it lies on OpenGL.org, and rewrite your code like this using only GLUT.
You need to add the glut32.lib to your projects link libraries and the glut32.dll into the applications folder.

This is one of the simplest GLUT applications I have with your clip planes added (though untransformed).

#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

int g_Width = 256;
int g_Height = 256;

void destroy(void)
{
exit(0);
}

void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);

glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glutWireSphere(1.0, 16, 16);
glPopMatrix();

glutSwapBuffers();
}

void reshape(int w, int h)
{
GLdouble eqn0[4] = {0.0, 1.0, 0.0, 0.0};
GLdouble eqn1[4] = {1.0, 0.0, 0.0, 0.0};

g_Width = w;
g_Height = h;

glViewport(0, 0, (GLsizei) w, (GLsizei) h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, 1.0f, 1.0f, 9.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Untransformed!
glClipPlane(GL_CLIP_PLANE0, eqn0);
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE1, eqn1);
glEnable(GL_CLIP_PLANE1);

glTranslatef(0.0f, 0.0f, -5.0f);
}


void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
destroy();
break;
case ' ':
glutPostRedisplay();
break;
default:
break;
}
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA);
glutInitWindowSize(g_Width, g_Height);
glutInitWindowPosition(0, 0);
glutCreateWindow(argv[0]);

init();

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();

return 0;
}Build this, run it, and see a quarter wire sphere in the top right quadrant.

When I said gluPerspective takes GLdouble I meant you should cast the integers w and h to that.

wile_spice
06-22-2006, 11:42 AM
ahhhh, same problems, I feel like I'm about to have an epileptic fit!!! Could it be possible that I corrupted the VC++ when I wrote that code because every program I build and compile is telling me it has 102 error, errors with the glaux library and I didn't even include it!!
I suspect you tested that code before you gave it to me and that it worked for you so I don't understand whats going on!

sqrt[-1]
06-22-2006, 06:47 PM
Perhaps you have made a mistake and edited your gl.h/glu.h/glut.h header files?

Perhaps when you had a compile error, you went to the line of the error (in one of these header files) and edited it manually?

wile_spice
07-06-2006, 10:59 AM
Sorry this took so long... I don't remember going to the code for the libraries until after I got these errors, but.... stuff happen and this is such a weird problem (ie I am getting errors for a library that I didn't include) so I decided to reinstall vc++ and see if that helps! Thanks alot to everyone who helped!!