Results 1 to 6 of 6

Thread: MSVC and data types in gl.h

  1. #1
    Guest

    MSVC and data types in gl.h

    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.

  2. #2
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: MSVC and data types in gl.h

    did you include windows.h before gl.h?

  3. #3
    Guest

    Re: MSVC and data types in gl.h

    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

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: MSVC and data types in gl.h

    Post your line of code at and around line 33...
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Guest

    Re: MSVC and data types in gl.h

    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,12;


    /* 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;
    }

  6. #6
    Member Contributor
    Join Date
    Oct 2001
    Posts
    67

    Re: MSVC and data types in gl.h

    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.

Similar Threads

  1. Kernel parameters / data types
    By fly_grz in forum OpenVX
    Replies: 3
    Last Post: 01-22-2015, 03:42 PM
  2. What is special about cl specific data types?
    By krishnan in forum OpenCL
    Replies: 2
    Last Post: 01-07-2011, 12:25 PM
  3. Data types
    By havok13888 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-07-2009, 01:44 PM
  4. OpenGL data types
    By Jameson Quave in forum OpenGL: Advanced Coding
    Replies: 20
    Last Post: 05-18-2006, 10:14 PM
  5. Data Types and Version
    By lost hope in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-05-2001, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean