#### Archived

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

# Optimization and loops

This topic is 5822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, first, my main question is... Can I have a look inside the glBegin() and glEnd() functions? For example glBegin(GL_POINTS); for (int counter = 0; counter < array.length(); counter++) glVertex3f(ArrayX[counter], ArrayY[counter], 0.0f); glEnd; and my second question... I am using the basic shell from nehe''s first tutorial, and the only thing I''m changing is the DrawGLScene function. my code is below. My question is, how could I make this faster? int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing { int newx = radius * cos(ConvertDegreesToRadians(angle)) + centerx; int newy = radius * sin(ConvertDegreesToRadians(angle-1.570795)) + centery; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef( -5.0f, 3.75f, -9.03f ); // Move Left 1.5 Units And Into The Screen 6.0 glBegin(GL_LINES); // Drawing Using Points glVertex3f(CONV_X float(centerx), CONV_Y float(centery), 0.0f); glVertex3f(CONV_X float(newx), CONV_Y float(newy), 0.0f); glEnd(); angle++; if(angle == 360) angle = 0; return TRUE; // Everything Went OK }

##### Share on other sites
(1) yes
(2) drawing one line should be plenty fast

In general though you can speed up geometry that doesn''t change using display lists and geometry that does change using vertex arrays etc. But get it correct before you get it optimized.

##### Share on other sites
Oh, it works. I have a line spinning in a circle (which''ll soon be a bunch of points spinning in a moving circle...)
I just wish it rotated a bit quicker. I know I can just incriment by two or three, but then it may become choppy.

##### Share on other sites
Nevermind, I can just incriment by two and the difference is not noticable.

Thanks for answering the first question though.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011260
• ### Who's Online (See full list)

There are no registered users currently online

×