Results 1 to 5 of 5

Thread: GLfloat array causes an error?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    3

    GLfloat array causes an error?

    Hey,

    I'm a beginner at OpenGL and not that great of a programmer. I'm compiling a pretty simple OpenGL/GLUT file under Windows using Visual Studio 2002 and I'm getting errors that I don't know how to fix.

    Here is the portion of the code that generates errors for me:

    glEnable(GL_DEPTH_TEST);

    // Enable a single OpenGL light.
    // White diffuse light.
    GLfloat light_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
    // Put the light at infinity in the direction (1,1,1)
    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    The compiler outputs:
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(167) : error C2275: 'GLfloat' : illegal use of this type as an expression
    c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(53) : see declaration of 'GLfloat'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(167) : error C2065: 'light_diffuse' : undeclared identifier
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(167) : error C2059: syntax error : '{'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2275: 'GLfloat' : illegal use of this type as an expression
    c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(53) : see declaration of 'GLfloat'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2146: syntax error : missing ';' before identifier 'light_position'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2143: syntax error : missing ';' before 'identifier'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2065: 'light_position' : undeclared identifier
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(169) : error C2059: syntax error : ']'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(170) : warning C4047: 'function' : 'const GLfloat *' differs in levels of indirection from 'int'
    c:\My Documents\Visual Studio Projects\Cube\Cube\cube.c(171) : warning C4047: 'function' : 'const GLfloat *' differs in levels of indirection from 'int'


    Every example file I've ever seen uses GLfloat in arrays. Any idea why my compiler seems to think this is illegal? Thanks!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: GLfloat array causes an error?

    Hi !

    Have you included gl.h ?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    3

    Re: GLfloat array causes an error?

    Hi!

    Thanks for the response. I did include gl.h

    Thanks!

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: GLfloat array causes an error?

    You're doing several things that aren't valid in C. Namely //-style comments and late temporary declarations. These things are only valid in C++.

    Remove the source file from your project. Then rename it to "cube.cpp". Readd it to the project. It should then compile fine.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    3

    Re: GLfloat array causes an error?

    Oh great you're right. Thanks so much! It works now.

Similar Threads

  1. How to use a big GLfloat array to display a dense mesh model?
    By ddguan in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-27-2014, 08:20 PM
  2. Compile error for float4 array
    By FredericX in forum OpenCL
    Replies: 4
    Last Post: 02-10-2011, 11:57 PM
  3. Indexed Vertex Array error (GL_INVALID_ENUM)
    By pontifikas in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-22-2009, 02:59 AM
  4. FBO + RTT array layer + newer drivers = error!
    By babis in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-27-2008, 03:39 PM
  5. Vertex Array Error
    By Rodrix in forum OpenGL: Advanced Coding
    Replies: 59
    Last Post: 05-23-2006, 01:24 AM

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