How draw pixels upon triangles

Hi,
I want draw pixels upon all other geometries, such as triangle. When I try it by calling glDrawPixels(), triangle dispaly upon pixels. What’s going wrong? Here is the drawing code:

    glBegin(GL_TRIANGLES);	
	glColor3f(1.0f, 0.0f, 0.0f);     glVertex2f(0.0f, 0.0f);
	glColor3f(0.0f, 1.0f, 0.0f);     glVertex2f(1.0f, 0.0f);
	glColor3f(0.0f, 0.0f, 1.0f);     glVertex2f(0.5f, 1.0f);
	glEnd();
	GLint width = 50;
	GLint height = 50;
	GLint PixelLength = 4 * width*height;
	PixelData = (GLubyte*)malloc(PixelLength);
	if (PixelData == 0)
		exit(0);
	for (int i = 0; i < width; i++)
	{
		for (int k = 0; k < height; k++)
		{
			PixelData[(i*width + k) * 4] = 255;
			PixelData[(i*width + k) * 4 + 1] = 0;
			PixelData[(i*width + k) * 4 + 2] = 0;
			PixelData[(i*width + k) * 4 + 3] = 100;
		}
	}
	
	glRasterPos3i(0.5, 0,0.5);
	glDrawPixels(width, height,
		GL_RGBA, GL_UNSIGNED_BYTE, PixelData);
	free(PixelData);

Thanks so much!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.