PDA

View Full Version : Error in creating some basic graphic.



Kurangceret
07-07-2013, 02:58 AM
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)

#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.

Nowhere-01
07-07-2013, 04:09 AM
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.

Kurangceret
07-07-2013, 04:29 AM
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 :).

Nowhere-01
07-07-2013, 04:33 AM
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.

Carmine
07-08-2013, 12:19 PM
[QUOTE=Kurangceret;1252486]


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,