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.
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.
// 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,’_’);