void OrthoList()
{
m_lstOrtoList = glGenLists(1);
glNewList(m_lstOrthoList, GL_COMPILE);
glPushMatrix();
/////////////////////////////////////////////////////////////
// Switch to an orthographic-view (non-perspiective) matrix.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 25.0, 25.0, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/////////////////////////////////////////////////////////////
glBindTexture(GL_TEXTURE_2D, m_unTextures[7]);
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f((GLfloat)dX1, (GLfloat)dY1);
glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)dX2, (GLfloat)dY2);
glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)dX3, (GLfloat)dY3);
glTexCoord2f(0.0f, 0.0f); glVertex2f((GLfloat)dX4, (GLfloat)dY4);
glEnd();
glDisable(GL_TEXTURE_2D);
/////////////////////////////////////////////////////////////
// Switch to a perspective-view matrix.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, m_dViewAspect, 0.1f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/////////////////////////////////////////////////////////////
glPopMatrix();
glEndList();
}
void DrawOpenGLScene(HWND hWnd)
{
ReleaseDC(hWnd, m_hDC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glCallList(lst1);
glCallList(lst2);
glCallList(lst3);
OrthoList();
glCallList(lstOrtoList);
}
// Picking method
#define BUFSIZE 512
GLuint selectBuf[BUFSIZE];
static LRESULT OnLButtonDown(HWND hWnd, UINT nFlags, POINT point)
{
//Selection Buffer
GLuint selectBuf[BUFSIZE];
//Number of Objects that we clicked on
int hits;
//create a viewport just for the selection
int viewport[4]; //0 - x, y - 1, length - 2, width - 3
// //set the viewport to the size and location of the screen
// glGetIntegerv( GL_VIEWPORT, viewport );
//set the viewport to the size and location of the screen
glGetIntegerv( GL_VIEWPORT, viewport );
//Tell OpenGL to use our array for selection
glSelectBuffer(BUFSIZE, selectBuf);
//put openGL in selection mode;
glRenderMode( GL_SELECT );
//initialize the name stack
glInitNames();
//push at least one entry on to the stack
glPushName(0);
//Now we're restricting drawing to just under the cursor. We need the projection matrix
//for this. Push it to the stack then reset the new matrix with load identity
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
//Now restrict drawing using gluPickMatrix(). The first parameter is our current
//mouse position on the x-axis, the second is the current mouse y axis. Then the width
//and height of the picking region. Finally the current viewport indicates the current boundries.
//mouse_x and y are the center of the picking region.
gluPickMatrix((GLdouble) point.x, (GLdouble)(viewport[3]-point.y), 1.0, 1.0, viewport );
//gluPerspective will restrict the drawing to the area requestd by gluPickmatrix()
//gluPerspective( 45.0f, (viewport[2] - viewport[0]) / (viewport[3] - viewport[ 1 ]), 0.1f, 100.0f );
gluPerspective( 45.0f, m_gldAspect, 0.1f, 500.0f );
//set the modelview to render our targets properly
glMatrixMode( GL_MODELVIEW );
// "render" the targets to our modelview
DrawOpenGLScene(hWnd);
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
//find out how many objects we hit
hits = glRenderMode( GL_RENDER );
//as long as we have more than 0, we select the first object drawn to the area.
if( hits != 0 )
{
int choose = selectBuf[3]; // Make Our Selection The First Object
int depth = selectBuf[1]; // Store How Far Away It Is
for (int loop = 1; loop < hits; loop++) // Loop Through All The Detected Hits
{
// If This Object Is Closer To Us Than The One We Have Selected
if (selectBuf[loop*4+1] < GLuint(depth))
{
choose = selectBuf[loop*4+3]; // Select The Closer Object
depth = selectBuf[loop*4+1]; // Store How Far Away It Is
}
}
}
return TRUE;
}
Switching to Ortho in list and picking, how?
Hi all,
is there a way that I can make a textured squad list which I render in 2D / ortho and the rest of the quad lists I render in my program in perspective view?
When I run the following (stripped) code the 2d squad list is rendered in 2D but I cannot pick any of the objects after it.
Who can I render some objects in 2D, some in 3D and still be able to pick the objects?
Can someone please help me with this?
If i where you i would use colorpicking instead. It's much simplier, fast, you don't have to worry about transforms.
color picking tutorial
color picking tutorial
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement