PDA

View Full Version : MSVC and data types in gl.h



08-07-2002, 02:40 PM
Hi!
I'm a linux user and i tried to compile a opengl/glut program with VC c++ 6, unfortunately i get a lot of errors like this:

Compiling...
main.c
C:\e\OpenGl\src\mouse\msv\main.c(33) : error C2275: 'GLfloat' : illegal use of this type as an expression
c:\archivos de programa\microsoft visual studio\vc98\include\gl\gl.h(53) : see declaration of 'GLfloat'
C:\e\OpenGl\src\mouse\msv\main.c(33) : error C2146: syntax error : missing ';' before identifier 'ambientLight'

My program works well under linux and i don't get any warning with the ansi flag with GCC, i tried differents gl.h or just including glut.h without gl.h but i still get the same error. I can compile any glut's example with no error.
thanks!
Luis.

no-one
08-07-2002, 05:09 PM
did you include windows.h before gl.h?

08-08-2002, 03:17 AM
yes, i did it... i have:

#include <windows.h>
#include <GL/glut.h>
#include "funcion.h"
#include "trackball.h"

And i get the same errors compiling the file with the main() function. Others files are: funcion.c and trackball.c

Deiussum
08-08-2002, 04:19 AM
Post your line of code at and around line 33...

08-08-2002, 06:35 PM
Ok! here is the entire file:
GLfloat ambientLight[]... is the line 33.
I really don't understand, i can compile funcion.c and trackball.c without errors and many others glut examples.

#include <windows.h>
#include <GL/glut.h>
#include "funcion.h"
#include "trackball.h"

#define ZOOM -3.5


/* mesh_list = glGenLists(1);
glNewList(mesh_list, GL_COMPILE);


glBegin(GL_QUADS);
glEnd();
glEndList();
*/

/* -------------------------------------------------------- */
/* This function does any needed initialization on the rendering
context. */
void SetupRC()
{
glEnable( GL_DEPTH_TEST ); /* Hidden surface removal */
glEnable( GL_POLYGON_SMOOTH );
glFrontFace(GL_CCW); /* Counter clock-wise polygons face out */

/* Light values and coordinates */
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat diffuseLight[] = { 0.9f, 0.9f, 0.9f, 1.0f };
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat lightPos[] = { 10.0f, 10.0f, 10.0f, 1.0f };
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };

/* Enable lighting */
glEnable(GL_LIGHTING);
/* Setup and enable light 0 */
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glEnable(GL_LIGHT0);

/* Enable color tracking */
glEnable(GL_COLOR_MATERIAL);

/* Set Material properties to follow glColor values */
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

/* All materials hereafter have full specular reflectivity
with a high shine */
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,specref);
glMateriali(GL_FRONT,GL_SHININESS,128);


/* Black background */
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

glNewList( AXES, GL_COMPILE );

draw_axes();

glEndList();

glNewList( FUNCTION, GL_COMPILE );

draw_function();

glEndList();

tbInit(GLUT_RIGHT_BUTTON);

}


void display(void)
{
/* Esto seria mi renderscene.
*/

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Clear the window with current clearing color */

glPushMatrix();

glTranslatef( 0.0f, 0.0f, ZOOM );
tbMatrix();


glCallList( AXES );
glCallList( FUNCTION );

glPopMatrix();

glFlush();
glutSwapBuffers();
}


/* -------------------------------------------------------- */
/* Change viewing volume and viewport. Called when window is resized */
void reshape (GLsizei w, GLsizei h)
{
/* Prevent a divide by zero */
if(h == 0) h = 1;
tbReshape(w, h);
/* Set Viewport to window dimensions */
glViewport(0, 0, w, h);

/* Reset projection matrix stack */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* Produce the perspective projection */
gluPerspective(60.0f, (GLfloat)w/(GLfloat)h, 1.0f, 20.0f);

/* Reset Model view matrix stack */
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

}


void keyboard(unsigned char key, int x, int y)
{
switch (key)
{

case 'f':glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glutPostRedisplay();
break;
case 'w':glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glutPostRedisplay();
break;
case 27: exit(0);
break;
}
}

void mouse(int button, int state, int x, int y)
{
tbMouse(button, state, x, y);
glutPostRedisplay();
}

void motion(int x, int y)
{
tbMotion(x, y);
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (400, 400);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Superficie 3D");
SetupRC();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
return 0;
}

secnuop
08-08-2002, 09:14 PM
If you're compiling this using the c compiler (not the c++ compiler), which is the default if your filename ends in .c, you'll need to do all of your declarations before your first statement. In other words, move the entire block of code commented "light values and coordinates" above where you enable the depth test.

Either that or compile with the c++ compiler. http://www.opengl.org/discussion_boards/ubb/smile.gif