VBO particles only rendering at 0,0

Hi, I’m writing a CUDA accelerated particle engine as a learning experience for both OpenGL and CUDA. I’ve got a good start, but I’m having problems with the rendering now. Everything was going fine until I switched from rending individual points to the VBO. Now things will only render at EXACTLY 0,0. It won’t even show up on the screen at 0.000001,0. I’m sure this is something to do with the camera matrix. Unfortunately I’m not sure how this works. Here is my code, I hope you can help me.

Thanks,

Craig Mouser


void display (void) {
	glClearDepth (1);
	glClearColor (0.3, 0.3, 0.3, 1.0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();  
	glTranslatef (0,0,-10);
	//UpdateParticles(mousePressed, mouseLocation.x, mouseLocation.y);
	DrawParticles();
	glutSwapBuffers();
	//glutPostRedisplay();

	//FPS Calculations
	finish = clock() ;
	duration += (double)(finish - start) / CLOCKS_PER_SEC ;
	frames ++ ;
	FPS = frames / duration ;
	start = clock() ;
	PrintFPS();
}

and the DrawParticles function:


void DrawParticles()
{
	glPointSize( ParticleSize );
	glPushMatrix();
	glEnable(GL_POINT_SPRITE);
	glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
	glEnable (GL_BLEND);  
	glBlendFunc (GL_ONE, GL_ONE);
	glBindTexture(GL_TEXTURE_2D, particleTexture[0]);
		glBindBuffer(GL_ARRAY_BUFFER, positionsVBO);
		glVertexPointer(4, GL_FLOAT, 0, 0);
		glEnableClientState(GL_VERTEX_ARRAY);
		glColor4f(particleColor.x, particleColor.y, particleColor.z, 1.0f);
		glDrawArrays(GL_POINTS, 0, ParticleCount);
		glDisableClientState(GL_VERTEX_ARRAY);
	glPopMatrix();
}

What kind of projection matrix are you using? Are you in the correct matrix mode when you you are calling your display() function. It’s kind of difficult to tell what is wrong from the code you have given.

I also have this code in the init:


	glEnable( GL_TEXTURE_2D );
	glEnable(GL_DEPTH_TEST);
	glViewport (0, 0, (GLsizei)WIDTH, (GLsizei)HEIGHT);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluPerspective (60, (GLfloat)WIDTH / (GLfloat)HEIGHT, 1.0, 100.0);
	glMatrixMode (GL_MODELVIEW);

Sorry, pretty new to this stuff, hope this helps.

Can anyone take a look at this? I’ll have some time to work on this tomorrow, but not for a while after that.

Thanks.

So I figured this out tonight, DrawParticles() will only draw the one at 0,0,0 exactly, while DrawParticles2() will draw all of them…


void DrawParticles()
{
	glPointSize( ParticleSize );
	glPushMatrix();
	glDisable (GL_DEPTH_TEST);
	glEnable(GL_POINT_SPRITE);
	glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
	glEnable (GL_BLEND);  
	glBlendFunc (GL_ONE, GL_ONE);
	glBindTexture(GL_TEXTURE_2D, particleTexture[0]);
		glBindBuffer(GL_ARRAY_BUFFER, positionsVBO);
		glEnableClientState(GL_VERTEX_ARRAY);
		glColor4f(particleColor.x, particleColor.y, particleColor.z, 1.0f);
		glVertexPointer(4, GL_FLOAT, 0, 0);
		glDrawArrays(GL_POINTS, 0, ParticleCount);
		glDisableClientState(GL_VERTEX_ARRAY);
	glEnable(GL_DEPTH_TEST);
	glPopMatrix();
}

void DrawParticles2()
{
    glPointSize( ParticleSize );
	glPushMatrix();
	glDisable (GL_DEPTH_TEST);
	glEnable(GL_POINT_SPRITE);
	glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
	glEnable (GL_BLEND);  
	glBlendFunc (GL_ONE, GL_ONE);
	glBindTexture(GL_TEXTURE_2D, particleTexture[0]);
	glBegin(GL_POINTS);
		for( int i = 0; i < ParticleCount; i++ )
        {
            glColor4f( 0.0f, 
                      0.0f, 
                       1.0f, 
                       0.7f );

	        glVertex3f( i,
                        i,
                        i);
        }
		glEnd();
	glEnable(GL_DEPTH_TEST);
	glPopMatrix();
}