Advertisement Jump to content


This topic is now archived and is closed to further replies.


openGL picking in special viewport.

This topic is 5334 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

i had implemented a perfectly working picking function based on the openGL picking system. My program is a rubik''s cube, and i use picking to determine the users moves. it was working fine when the viewport i drew the cube in was basically the window - glViewport(0, 0, width, height) - but because i have menues on the right hand side of my app, i changed the viewport so my cube would be drawn in the middle of the window space left after menu and console drawing. here is the code : # void CCamera:osition3DCamera(void) # { # GLfloat width = (GLint)(m_wndDim.getW() - m_offset3D.getW()); # GLfloat height = (GLint)(m_wndDim.getH() - m_offset3D.getH()); # # glViewport(0, m_offset3D.getH(), (GLint)width, (GLint)height); # glMatrixMode(GL_PROJECTION); # glLoadIdentity(); # gluPerspective(45.0f, width/height, 1.0f, 100.0f); # glMatrixMode(GL_MODELVIEW); # glLoadIdentity(); # } with m_wndDim being the current window dimensions, and m_offset3D.getW equal to my menu width (on the right hand of the screen), and m_offset3D.getH equal to my console height. i have an other function to set the viewport and projection for 2D rendering (console and all). # void CCamera:osition2DCamera(void) # { # glViewport(0, 0, m_wndDim.getX(), m_wndDim.getY()); # glMatrixMode(GL_PROJECTION); # glLoadIdentity(); # gluOrtho2D(0.0f, m_wndDim.getX(), 0.0f, m_wndDim.getY()); # glMatrixMode(GL_MODELVIEW); # glLoadIdentity(); # } since i''ve made this slight change, my picking function doesn''t work anymore (at all). here is the picking function (not all of it, only the interesting part) : # glSelectBuffer(512, selectBuffer); # glGetIntegerv(GL_VIEWPORT, viewportCoords); # # glMatrixMode(GL_PROJECTION); # glPushMatrix(); # # glRenderMode(GL_SELECT); # glLoadIdentity(); # # gluPickMatrix(m_mouseState.m_currentPos.getX(), viewportCoords[3] - m_mouseState.m_currentPos.getY(), 3.0, 3.0, viewportCoords); # gluPerspective(45.0f, (GLfloat)m_wndDims.getX()/(GLfloat)m_wndDims.getY(), 0.1f, 100.0f); # glMatrixMode(GL_MODELVIEW); # # m_camera.position3DCamera(); # m_cube.renderForSelection(); # # objectsFound = glRenderMode(GL_RENDER); # glMatrixMode(GL_PROJECTION); # glPopMatrix(); # glMatrixMode(GL_MODELVIEW); i know the problem comes from the gluPerspective() function, but ive tried replacing it with the CCamera:osition3DCamera(), but it doesn''t work. any help woulb be greatly appreciated, this project being due tomorrow... :/ thxs again

Share this post

Link to post
Share on other sites
ok, i''ve actually found the solution to my problem
I don''t have too much time tu write it out here, but once my project is done, i''ll post the solution.

Might help someone else ^^

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!