Jump to content
  • Advertisement
Sign in to follow this  
Scanmaster_k

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.

If you intended to correct an error in the post then please contact us.

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);
	glLoadIdentity();

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

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Scanmaster_k
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


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Scanmaster_k
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


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!