Advertisement

NeHeGL 2 problem

Started by March 04, 2002 04:39 PM
8 comments, last by Greven 22 years, 11 months ago
I''m just getting into OpenGl after many years of hating D3D Found the NeHeGL 2 base code which is just a dream come true, if I could get it to work! I''ve added the following code to the Draw function in the example and it just won''t draw the damn line!

glLoadIdentity();
glTranslatef(0.0f,0.0f,0.0f);
glRotatef(rot,1.0f,1.0f,1.0f);
glBegin(GL_LINES);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-10.0f,-10.0f,0.0f);
glVertex3f(0.0f,10.0f,0.0f);
//glVertex3f(10.0f,-10.0f,0.0f);

glEnd();
 
It was originally supposed to be a triangle, but I thought I''d simplify it with a line... The app compiles fine, and runs, just no line. oh, and rot is a static float that I add 0.2f to every call. I did a search on this, and found a few other people with this problem, but no solution... Anyone? That brings up a second question, what is the winding on the triangles by default in OGL? CW or CCW? Always remember, you''''re unique. Just like everyone else.
Always remember, you''re unique. Just like everyone else.Greven
You have to move into the screen before drawing the lines, eg instead of calling glTranslatef(0.0f, 0.0f, 0.0f), try to call glTranslatef(0.0f, 0.0f, -10.0f).

BTW glTranslate(0,0,0) is absolutely useless

The default winding is CCW in OpenGL.

And if you want to draw a triangle with lines, I recommend GL_LINE_LOOP instead of GL_LINES.

GL_LINES on 4 vertices joins vertex 1 to vertex 2, and vertex 3 to vertex 4
GL_LINE_STRIP on 4 vertices joins vertex 1 to vertex 2, vertex 2 to vertex 3, and vertex 3 to vertex 4
GL_LINE_LOOP on 4 vertices joins vertex 1 to vertex 2, vertex 2 to vertex 3, vertex 3 to vertex 4, and vertex 4 to vertex 1

So, if you work with 3 vertices :
GL_LINES will join vertex 1 to vertex 2, and will ignore vertex 3 ; whereas GL_LINE_LOOP will join vertex 1 to vertex 2 to vertex 3 to vertex 1.

Hope this helps.
Advertisement
Well, I changed the translate to 0,0,-10 and still nothing... I took out the rotation code now, to simplify even further... Here is my entire Draw function, maybe it's somewhere else.

void Draw (void){	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();	glColor3f(0.0f,0.3f,1.0f);	fNehe.SetBase(32);	fNehe.Print(20,30,"NeHe Productions Presents:");	glColor3f(1.0f,1.0f,0.0f);	fNehe.SetBase(32 - 128);	fNehe.Print(20,50,"NeHe Base Code Version 2.0");	glLoadIdentity();	glTranslatef(0.0f,0.0f,-20.0f);	glBegin(GL_LINE_LOOP);	glColor3f(1.0f,0.0f,0.0f);	glVertex3f(-10.0f,-10.0f,0.0f);	glVertex3f(0.0f,10.0f,0.0f);	glVertex3f(10.0f,-10.0f,0.0f);	glEnd();	glFlush ();}  


Thanks for the help btw...

Always remember, you''re unique. Just like everyone else.

Edited by - Greven on March 4, 2002 5:56:37 PM
Always remember, you''re unique. Just like everyone else.Greven
Maybe you''re drawing too big.

First of all, try to replace GL_LINE_LOOP by GL_TRIANGLES.
If a full red screen appears, that means the triangle entirely overlap the screen, so the borders of the triangles are not visible, which would explain why you would not see the lines (ie using GL_LINE_LOOP). In that case, the simple solution is either to reduce the triangle coordinates from 10.0f to eg 1.0f, or use the scale command glScalef(0.1f, 0.1f, 0.1f);

Secondly, I don''t think your "Print" calls draw anything. Do they ?
quote:
Original post by vincoof
Maybe you''re drawing too big.

First of all, try to replace GL_LINE_LOOP by GL_TRIANGLES.
If a full red screen appears, that means the triangle entirely overlap the screen, so the borders of the triangles are not visible, which would explain why you would not see the lines (ie using GL_LINE_LOOP). In that case, the simple solution is either to reduce the triangle coordinates from 10.0f to eg 1.0f, or use the scale command glScalef(0.1f, 0.1f, 0.1f);

Secondly, I don''t think your "Print" calls draw anything. Do they ?


Tried it, nothing.
And yes, the print calls are part of the font class in the basecode. This is all from NeHeGL 2 basecode. Tried it with GL_LINES, GL_LINE_LOOP, and GL_TRIANGLES now. nothing... Also tried with coordinates of 1''s thinking maybe I''d at least get a dot... nothing.

Anyone know what''s going on?

Always remember, you''''re unique. Just like everyone else.
Always remember, you''re unique. Just like everyone else.Greven
Hmm.... try using any of the OpenGL basecodes. The Nehe 2 one isn''t made by Nehe, so he might not have an idea of the problem. It shouldn''t be a problem if you use the OpenGL Basecode (normal).
Advertisement
What parameters do you have in gluPerspective?

And where you have -10 and 10 in glVertex ... change them to -2 and 2 - I''m sure what you are drawing should be on screen, but I couldn''t swear to it - it depends on the perspective function.
To see if the rendering context is intialized correctly, use this only-for-test drawing code :

glClear(GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D); // if your OpenGL supports it
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
glDisable(GL_CLIP_PLANE4);
glDisable(GL_CLIP_PLANE5);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glVertex2i(-1,-1);
glVertex2i(+1,-1);
glVertex2i(+1,+1);
glVertex2i(-1,+1);
glEnd();
glFlush();

You have to see a full white screen.
change the color into glColor and the color has to change.
If this does not work, then I think the context is not initialized correctly.

Edited by - vincoof on March 5, 2002 3:48:17 AM
Wait a sec, doesn''t the nehegl code use it''s own swap buffer routine? Shouldn''t he be using something other than glFlush? Don''t know for sure though...

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Calling glFlush twice can not harm the program.

glFlush does not flushes the pixels to the screen. It ensures that all pixels to be drawn are drawn in a finite time, ie you will be able to use the frame buffer (for example to push it on screen, or to read some pixels using glReadPixels) after glFlush is called.

But if you do not call glFlush, you have no guarantee that OpenGL will have performed all operations before the framebuffer is sent to the screen, which can yield some awful effects.

This topic is closed to new replies.

Advertisement