Figuring out near clipping plane based on screen resolution

Started by
5 comments, last by gpu_fem 14 years, 10 months ago
I'm rendering a uniform grid of points and want them to render more when the screen is changed to a higher resolution. The problem I'm having is figuring out where the near clipping plane should be to render the points without gaps in between them at higher resolutions. What would be the formula for figuring out the near clip plane for my situation? Help would be appreciated, thanks.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Advertisement
If you are just rendering a grid of points on the screen? Then can't you do something like

int v[4];
glGetv(GL_VIEWPORT, v);

glPushMatrix();
glLoadIdentity();

// right,left,top,bottom are the near clip plane bounds
glBegin(GL_POINTS);
for (int i = 0; i < v[2]; i++)
for (int j = 0; j < v[3]; j++)
glVertex3f((right-left)*i / (v[2]-1)+left,(top-bottom)*j / (v[3]-1)+bottom, zNear);

glEnd();

Or are you trying to do a projected grid (like for water)?
Well I'm trying to render a 3D grid of points, which I should have said before, anyways, they're in 3D space but I want to render them at a 1 point per pixel for a chosen resolution, but there will be gaps between them if they get too close to the camera for a given resolution. So the near clip plane should be smaller for low resolutions and higher for higher resolutions, I just don't know how I could figure it.

for instance if I had a 2D grid, but in 3d space, of points each equal in distance from each other at a grid size of 1024x768, I'd want them to be directly mapped to the correct pixel if I was viewing it from the center x and y axis at a 1024x768 resolution. I forgot to mention that the FOV is 45 degrees.

So, ya, I guess I mean a projected grid, lol.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Sure. I think my previous code will do that. (I forgot glPopMatrix() ) at the end. What it does is get the size of the viewport (which tells you how many pts to render), and places them on the near clipping plane (whose x,y size is specified by the clipping planes left/right/top/bottom). You may have to change zNear to zNear*1.0001 or something like that to compensate for floating point errors. At the start of the code, I do a glPushMatrix() followed by glLoadIdentity() to make the model transformation identity. This is necessary because the vertices supplied are already in eye coordinates!
K, I'll see if I can convert that to something that will work in XNA.

Thanks for helping with my issue, I'm quite the graphics programming noob, or programming noob in general lol, I should find a new hobby.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Ok, after actually looking up the opengl functions to see what they do, I don't think what you're doing is what I need. It looks like you're plotting a vertex per screen pixel no matter where the near clipping plane is. Maybe I'm wrong, I don't know openGL that well. What I'm really trying to do is make entire 3D environments with just using points for geometry/surfaces. So, what I want to do is render pre-plotted points that describe a surface, I just don't want the points to render oddly when they're too close to the camera for a given resolution.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
I think I understand - you want to render points that lie on a surface, but with a density so that the get projected equally spaced on the screen. When people render water, they render one quad for every 2 pixels (e.g.), and project the vertices onto the z=0 plane in order to calculate color, position, etc. If this is what you are looking for , search "projected grid water".

Or are you merely trying to place the clipping plane so that areas of the surface with less than one vertex/pixel get clipped out?

This topic is closed to new replies.

Advertisement