Special polygon question...

I want to know how to set it up to draw a textured quad from the standard screen coordinates.

Like…drawing a quad from (0,0)-(320,200) or something…so that it’s drawn flat…

I’m thinking of this because I want to make a drop-down console, ala Quake. I already have the scripting done and everything. It’s just a matter of drawing the menu gfx.

  • Derek Doucett

int gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *objx, GLdouble *objy, GLdouble *objz);

This will get you the 3D coordinate from a 2D-window coordinate. Just get the four coordinates and put a Quad using those four coordinates as the vertices.

Winz is supposed to be 0.0 if you plan on putting the Quad on the near clipping plane. You may have to use a winz>0 (like 0.001) so that the Quad isn’t clipped.

I’d just change the projection to an orthographic one. Just push the projection matrix, and view matrix (if they need saving). Load the projection matrix with the identity matrix, use glOrtho to set up the orthographic projection, load the view matrix with the identity matrix. Then disable depth testing and depth writes and draw the quad at any depth. This would be one of the last things I’d draw except for any text that would go on top of it. And then finally pop the view and projection matrices off the stacks if they were saved earlier.

That sounds exactly what I’m looking for
Now I’m still sorta a newbie to OpenGL.
Could you provide me with some code?

  • Derek Doucett

Sure, I ripped this out of an old game engine I never finished It could use a good deal of tidying.

void DrawConsole()
{
if(!fontshader | | !fontshader->numlayers)
return;

switch(consolestate)
{
case con_up:
return;
case con_moving_up:
con_y+=deltatimeCONSOLE_SPEED/1000.0;
if(con_y>=25.0)
{
con_y=25.0;
consolestate=con_up;
return;
}
break;
case con_moving_down:
con_y-=deltatime
CONSOLE_SPEED/1000.0;
if(con_y<=con_y_target)
{
con_y=con_y_target;
consolestate=con_down;
}
break;
case con_down:
break;
}

glDisable(GL_DEPTH_TEST);

glPushMatrix(); // saves the model matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // saves the proj matrix

glLoadIdentity();
glOrtho(0.0,80.0,0.0,24.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND);
if(dropto==CONSOLE_DROP_FULL)
glColor4fv((float*)&color_white);
else
glColor4fv((float*)&color_white_halfalpha);

// draw the console background
if(console_bkg && console_bkg->numlayers)
{
glBindTexture(GL_TEXTURE_2D,console_bkg->layers[0]->gltexbind);
glBlendFunc(console_bkg->layers[0]->blendsrc,console_bkg->layers[0]->blenddest);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex3f(0.0,con_y,0.0);
glTexCoord2f(1.0,0.0);
glVertex3f(80.0,con_y,0.0);
glTexCoord2f(1.0,1.0);
glVertex3f(80.0,25.0,0.0);
glTexCoord2f(0.0,1.0);
glVertex3f(0.0,25.0,0.0);
glEnd();
}
if(dropto!=CONSOLE_DROP_FULL)
glColor4fv((float*)&color_white);
// draw console text
render_char_parm parms;
parms.y=con_y+1;
parms.color4=(float*)&color_white;
glBindTexture(GL_TEXTURE_2D, fontshader->layers[0]->gltexbind);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
list<string >::iterator lnit;
for(lnit=console_lines.begin();lnit!=console_lines.end();++lnit)
{
parms.x=0;
string pstr=lnit;
int len=pstr->length();
if(len<1)
continue;
if(len>80)
len=80;
char c=console_scratch;
memcpy(console_scratch,pstr->c_str(),len+1);
for(int i=0;i<len;i++,c++)
{
switch(c)
{
case ‘\r’:
break;
case ’
':
case ’ ':
parms.x++;
break;
case ’ ':
parms.x+=8.0;
break;
case 1:
parms.color4=(float
)&color_red;
break;
case 2:
parms.color4=(float
)&color_green;
break;
case 3:
parms.color4=(float
)&color_blue;
break;
case 4:
parms.color4=(float
)&color_yellow;
break;
case 5:
parms.color4=(float
)&color_magenta;
break;
case 6:
parms.color4=(float*)&color_cyan;
break;
case 7:
parms.color4=(float*)&color_white;
break;
default:
Con_DrawChar(&parms,*c);
parms.x++;
}
}
parms.y++;
if(parms.y>25.0)
break;
}

// draw current cmd text (only last 79 characters of it)
int len=current_cmd_line.length();
int start;
if(len>79)
{
start=len-79;
len=79;
}
else
start=0;
parms.color4=(float*)&color_green;
parms.x=0;
parms.y=con_y;
for(int j=0;j<len;j++)
{
char ck=current_cmd_line[start+j];

  switch(ck)
  {
  case '\r':
  case '

':
case ’ ‘:
parms.x++;
break;
case ’ ‘:
break;
case 1:
parms.color4=(float*)&color_red;
break;
case 2:
parms.color4=(float*)&color_green;
break;
case 3:
parms.color4=(float*)&color_blue;
break;
case 4:
parms.color4=(float*)&color_yellow;
break;
case 5:
parms.color4=(float*)&color_magenta;
break;
case 6:
parms.color4=(float*)&color_cyan;
break;
case 7:
parms.color4=(float*)&color_white;
break;
default:
Con_DrawChar(&parms,ck);
parms.x++;
}
}
// ok draw key cursor
parms.color4=(float*)&color_green;
Con_DrawChar(&parms,’_’);

// all done, restore previous matrices
glColor4fv((float*)&color_white);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glEnable(GL_DEPTH_TEST);

}

[This message has been edited by DFrey (edited 06-23-2000).]