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

Started by
6 comments, last by clrscr 22 years, 4 months ago
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
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
Advertisement
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.
You don''t need to change the value in glTranslate(). It translates from where it last was so you just need this glTranslatef( 0.0f, 0.1f, 0.0f );
That fixed it, thanks a lot jacksonh

"You can observe a lot just by watching."- Yogi Berra
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
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.
as a follow on to the previous post, if you were using static for speed, use register instead. Go''s faster anyway.

register float down=0.0f;


Beer - the love catalyst
Beer - the love catalystgood ol' homepage
as a follow on to the previous post, if you were using static for speed, use register instead. Go''s faster anyway.

register float down=0.0f;


Beer - the love catalyst
Beer - the love catalystgood ol' homepage
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
------------------------------Put THAT in your smoke and pipe it

This topic is closed to new replies.

Advertisement