Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Error in creating some basic graphic.

  1. #1
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    2

    Error in creating some basic graphic.

    So, I started to learn Open GL a bit in Visual Studio 2010, then when I use some basic command to create a simple 2d graphics, error came out from GL_LINES, same goes to other 2d command except the GL_POINTS.(And I tried 3d command and somehow it worked)
    Code :
    #include <GL/freeglut.h>
    #include <stdlib.h>
    #include <conio.h>
     
     
    static void 
    resize(int width, int height)
    {
        const float ar = (float) width / (float) height;
     
        glViewport(0, 0, width, height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
     
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity() ;
    }
    void userdraw()
    {
    	glBegin;
    	GL_LINES(100,50);
    	glEnd();
     
    	glPushMatrix();
    	glutWireTorus(0.3,0.6,15,15);
    	glPopMatrix();
    }
     
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	userdraw();
    	glutSwapBuffers();
    }
    int main (int argc, char**argv)
    {
    	glutInit(&argc,argv);
    	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    	glutInitWindowPosition(100,100);
    	glutInitWindowSize(1000,700);
    	glutCreateWindow("Test");
    	//glClearColor(1.0,1.0,0.0,0.0);
     
    	glutIdleFunc(display);
    	glutDisplayFunc(display);
    	glutMainLoop();
    	getch();
    	return 0;
    }
    Then I hover to GL_LINES command, and the system says
    "define GL_LINES 0x0001"
    "Error Expression must have a (pointer-to-)function type.
    Anyone can give me some advice ? Would appreciate it a lot.

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    GL_LINES(as well, as GL_POINTS and many other names with GL_ prefix) is a compile-time constant, declared in OpenGL-headers to pass it as an argument to OpenGL functions. you, or whoever written this code, decided it's a good idea to declare a function with the same name. it's declared somewhere outside of source code you've posted, but you use it. however, from the standpoint of a programming language and common sense, it is a really stupid idea and it leads to a conflict.
    Last edited by Nowhere-01; 07-07-2013 at 04:16 AM.

  3. #3
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    2
    Quote Originally Posted by Nowhere-01 View Post
    GL_LINES(as well, as GL_POINTS and many other names with GL_ prefix) is a compile-time constant, declared in OpenGL-headers to pass it as an argument to OpenGL functions. you, or whoever written this code, decided it's a good idea to declare a function with the same name. it's declared somewhere outside of source code you've posted, but you use it. however, from the standpoint of a programming language and common sense, it is a really stupid idea and it leads to a conflict.
    Mmmm.... to be fair I am confused :/, do you mean that I should make another file and define it there? I am sorry but I got a hard time understanding what you mean.
    EDIT: got it fixed, thanks anyway .
    Last edited by Kurangceret; 07-07-2013 at 04:37 AM.

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    GL_LINES(100,50); <---- this

    you named a function "GL_LINES". this name is already occupied with OpenGL variable. choose a different name. find, where it's declared and rename it.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    177
    [QUOTE=Kurangceret;1252486]
    Code :
    void userdraw()
    {
    	glBegin;
    	GL_LINES(100,50);
    	glEnd();
     
    	glPushMatrix();
    	glutWireTorus(0.3,0.6,15,15);
    	glPopMatrix();
    }

    Read the description of glBegin again and look at some examples.
    Your basic syntax is incorrect. Read manual on glVertex too.
    You probably don't need the Push and Pop around the Torus command,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •