OpenGL OpenGL cooridnates

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

Recommended Posts

Hi Im new at opengl and Im trying to set up a window to be able to handle some basic 3d drawing. The problem is with the coordinates. The origin (0, 0, 0) is in the center of the screen but I want it down at the left corner of my window. This is how I initializes openGL.
const bool CRenderer::initialize(const HDC dc, const GLsizei width, const GLsizei height)
{
bool isSuccessfull = true;
mhDC = dc;

setupPixelFormat();
mhRC = wglCreateContext(mhDC);

if(wglMakeCurrent(mhDC, mhRC) == false)
{
isSuccessfull = false;
}

mWidth = width;
mHeight = height;

glViewport(0, 0, mWidth, mHeight);
glMatrixMode(GL_PROJECTION);

gluPerspective(55.0, static_cast<GLdouble>(mWidth / mHeight), 1.0, 100.0);

glMatrixMode(GL_MODELVIEW);

glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);

return(isSuccessfull);
}

Thanks for any help Scanmaster_K

Share on other sites
That doesn't really make sense if you are using a perspective viewport. Any object drawn in 0,0,0 in camera space will either be clipped or fill the entire viewport (unless its a point or a line in which case it is interminate).
This is because the x and y screen coordinates (those used to actually draw the pixels) are calculated like this: xs = (x*m)/z, ys = (y*m)/z (m is a muiltiplicative factor in there to adjust for field of view)
As you can see, if z is zero then xs and ys are indeterminate. This is why when drawing using a perspective viewport the near clipping plane is set to greater than 0.0.
Explain what it is you are trying to draw and we can help you more easily.

Share on other sites
Well I just heard that 0.0 down in the left corner was openGL standard so I thought I was doing something wrong but apperently not.

Thanks

Share on other sites
Quote:
 Original post by Scanmaster_kWell I just heard that 0.0 down in the left corner was openGL standard so I thought I was doing something wrong but apperently not.Thanks

Try using glOrtho2D() instead of gluPerspective(), this will put you in ortho mode, which is basically a 2-dimensional mode.

Share on other sites
IF you would have really wanted that, the key would be to not use gluPerspective but glFrustum. But using a non-symmetric frustum would probably be a bit unusual anyway.

Share on other sites
Quote:
 Original post by Scanmaster_kWell I just heard that 0.0 down in the left corner was openGL standard so I thought I was doing something wrong but apperently not.Thanks

That sounds like texture mapping. (0,0) texture coordinates are indeed the lower left.

If you are actually referring to perspective mode, then you might try rendering everything at worldspace 0,0,0 but position and point your camera using gluLookAt() so that it all appears in the lower left of the viewport. Like eveyone else, seem kind of odd though.

hth
F451

• What is your GameDev Story?

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

• 14
• 11
• 29
• 15
• 41
• Forum Statistics

• Total Topics
634838
• Total Posts
3019568
×