OpenGL help?

Hello everyone!
I'm trying to code a 1980's Asteroids type game in OpenGL and I'm almost done, however one thing is really bugging me, and I can't seem to see what the problem is? I'm trying to draw 'stars' by drawing a hundred points at random coordinates using a drawStars function. Here is the code for the function:

1
2
3
4
5
6
7
8
9
10
  void drawStars(int numofstars)
{

	int yS = rand();
	int xS = rand();
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_POINTS);
	glVertex2f( xS, yS);
	glEnd();
}


and when I call the function in the DISPLAY function, I just simply put:
drawStars(100);

Thanks guys!
You accidentally your loop. Notice how the variable you pass into your function isn't actually being used in that function? Seems kind of strange doesn't it?
Do this

1
2
3
4
5
6
7
8
9
10
11
void drawStars(int numofstars)
{
        for(int i = 0; i < numofstars; ++i){
	        int yS = rand();
	        int xS = rand();
	        glColor3f(1.0, 1.0, 1.0);
	        glBegin(GL_POINTS);
	        glVertex2f( xS, yS);
	        glEnd();
        }
}
Thanks for the help, the for loop worked fine. Going to kick myself now, so simple!
Topic archived. No new replies allowed.