Archived

This topic is now archived and is closed to further replies.

clrscr

Is there anything wrong with this code? (Its short)

Recommended Posts

I''m trying to draw 80 lines on the screen each line a little bit lower the the other (I know its dumb, but hey I''m just starting out. However, it looks like this code isn''t drawing anything. Heres the code: int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing { static float down = 0.0f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity(); glTranslatef(0.0f,0.0f,-10.0f); glColor3f(1.0f,0.0f,0.0f); for(int i = 0;i<80;i++) { glTranslatef(0.0f,-down,0.0f); glBegin(GL_LINES); glVertex3f(-10.0f,0.0f,0.0f); glVertex3f(10.0f,0.0f,0.0f); glEnd(); down+=0.10f; } return TRUE; // Everything Went OK } BTW- How do you get code to have that white box with syntax highlighting and such. "You can observe a lot just by watching."- Yogi Berra

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m not opengl guru, but I can tell one of your problems is that you are probably drawing off the edge of the screen. With identity view and default projection, I think the screen is small (about 1x1 units) so it is easy to draw off of it.

Share this post


Link to post
Share on other sites
Since others have solved your problem I will mention one small problem with what you have coded that may surface elsewhere in your code.

You declare down with
static float down = 0.0f

What this does is ensure that down only gets initialized once in your entire program, so the second time you call this function down will start at 8.0f (0.0f + 0.1f*80)

You should just be using
float down - 0.0f
in these kinds of situations as that will ensure it gets set to zero every time you call the method.

Share this post


Link to post
Share on other sites
quote:
Original post by clrscr
BTW- How do you get code to have that white box with syntax highlighting and such.

"You can observe a lot just by watching."- Yogi Berra


You put the word "source" inside of the brackets. ] and [, or [].
      
int DrawGLScene(GLvoid)
// Here's Where We Do All The Drawing

{
static float down = 0.0f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity();
glTranslatef(0.0f,0.0f,-10.0f);
glColor3f(1.0f,0.0f,0.0f);
for(int i = 0;i<80;i++)
{
glTranslatef(0.0f,-down,0.0f);
glBegin(GL_LINES);
glVertex3f(-10.0f,0.0f,0.0f);
glVertex3f(10.0f,0.0f,0.0f);
glEnd();
down+=0.10f;
}

return TRUE;
// Everything Went OK

}


If that's what you meant. You can click "edit" on my post and see how I did it.


Edited by - Drizzt DoUrden on December 15, 2001 10:43:04 AM

Share this post


Link to post
Share on other sites