# Figuring out near clipping plane based on screen resolution

This topic is 3526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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();

// 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)?

##### Share on other sites
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.

##### Share on other sites
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!

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634146
• Total Posts
3015772
×