3D Pixels won't show up

Started by
5 comments, last by Gice 19 years, 4 months ago
Alright so I have a totally n00b question but based on the positive response I've received so far I am going to dare to ask.. I've looked at a whole bunch of example code and I can follow it without problems. Right now I'm taking an example program and I threw in a couple of lines to add some pixels in 3D to the scene, after it renders the other objects in the scene, and before it flips the back buffer to the screen. I.e. my code looks something like this (from memory): glBegin(GL_POINTS); for (int i=0;i<5000;i++) { glColor3i(rand()%255,rand()%255,rand()%255); glVertex3i(256-rand()%512,256-rand()%512, 256-rand()%512)); } glEnd(); so i'm thinkin.. this should draw 5000 randomly colored pixels within a sphere (Ed : er.. cube, sorry) of 256 radius with origin at the origin, right? Well, my pixels don't show up in the scene. I've had it to where only pixels that lie on the zy plane show up (i.e. with z = 0) which I guess has something to do with depth testing or something.. Now I do not profess to understand the OpenGL state machine and I know it's probably something silly, but I can't figure it out. Is there a state that needs to be enabled for these pixels to show up in 3D? I'm sorry, I know it's probably a dumb question! [Edited by - Gice on December 1, 2004 10:51:52 AM]
There can be only one.
Advertisement
Actuarly it would draw 5000 randomly colored pixels with in a cube of (512,512,512).

As for the other problem, you have to increase the z-far variable to aproximatly 1000, right now it's probobly at 1.

To do that you have to find the place where you set up your projection matrix(look for this line glMatrixMode (GL_PROJECTION);).
and then modify or add one of these depending on what projection you want/have.
gluPerspective (45.0f, (GLfloat)(width)/(GLfloat)(height),1.0f, 1000.0f);
or
glOrtho( 0, x , y , 0, 1, 1000 );

note: if you allready have one of these then you only have to set the last value to 1000.
Correction to myself ; I realized it would draw in a cube not a sphere, my bad.
There can be only one.
thanks Overlord... I'll give that a shot..
There can be only one.
Hm.. as I thought, that wasn't it...
There can be only one.
You say you're rendering this after you render some other objects. Can you post your full rendering loop?

Enigma
Eureka! I got it to work after I disabled depth testing and lighting. (DOH)

Thanks enigma and lc_overlord for taking time to try and help :)
There can be only one.

This topic is closed to new replies.

Advertisement