PDA

View Full Version : GL_LINES() draws a triangle but no line



grillstern
07-12-2012, 01:04 AM
Hi. Some days ago a started getting familiar with openGL. My problem so far: I just want to draw a simple line on the Y-axis with this code:



glBegin(GL_LINES);
glVertex3f(0, 10, 0);
glVertex3f(0, -10, 0);
glEnd
;

but unfortunately when rendering, i got no line, but instead a triangle on its position (the big sphere in the middle is placed on 0,0,0 / center):

http://i47.tinypic.com/2ealcnk.jpg

the main() and rendering() code so far:


void renderScene(void) {

if (deltaMove) {
computePos(deltaMove);
}
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

// Reset transformations
glLoadIdentity();

// Set the camera
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0.0f, 1.0f, 0.0f);

// Draw a Line
glBegin(GL_LINES);
glVertex3f(0, 10, 0);
glVertex3f(0, -10, 0);
glEnd;
// glPopMatrix();

// Draw "Stars"
for (int i = 0; i < lstVectors.size(); i++) {
glPushMatrix();
glTranslatef(lstVectors.at(i)->GetX(), lstVectors.at(i)->GetY(), lstVectors.at(i)->GetZ());
drawSphere();
glPopMatrix();
}
glutSwapBuffers();
}

int main(int argc, char **argv) {

// initVektors();
LoadStars();

// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Star GL");

// register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutIgnoreKeyRepeat(1);
glutKeyboardFunc(keyboard);
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);

// here are the two new functions
glutMouseFunc(mouseButton);
glutMotionFunc(mouseMove);

// OpenGL init
glEnable(GL_DEPTH_TEST);

// enter GLUT event processing cycle
glutMainLoop();

return 1;
}

...anyone can tell me how i get real lines? :-)

Dark Photon
07-12-2012, 05:05 AM
My problem so far: I just want to draw a simple line on the Y-axis with this code:



glBegin(GL_LINES);
glVertex3f(0, 10, 0);
glVertex3f(0, -10, 0);
glEnd;

Ditch your compiler. It's garbage. Even an ancient GCC from 5 years ago will catch this error. And even that's with just the default warnings, not every warning possible enabled.

You want "glEnd()", not "glEnd".

grillstern
07-13-2012, 08:12 AM
Oh... Thx for this!
Didn't noticed this error in my code! :whistle: