PDA

View Full Version : look: half life 2 onscreen panels!!



JernejL
05-02-2005, 11:04 PM
procedure drawwindowframe(x, y, w, h: single);
begin
glcolor4ub(255, 255, 255, 255);
glFrontFace(GL_CW);
glBindTexture(gl_texture_2d, win.GLID);

// TOP one
glBegin(gl_quads);
glTexCoord2f(F0, FC); glvertex2fwin(x, y);
glTexCoord2f(F0, FB); glvertex2fwin(x, y + winframe);
glTexCoord2f(FA, FB); glvertex2fwin(x + winframe, y + winframe);
glTexCoord2f(FA, FC); glvertex2fwin(x + winframe, y);

glTexCoord2f(FA, FC); glvertex2fwin(x + winframe, y);
glTexCoord2f(FA, FB); glvertex2fwin(x + winframe, y + winframe);
glTexCoord2f(FB, FB); glvertex2fwin(x + w - winframe, y + winframe);
glTexCoord2f(FB, FC); glvertex2fwin(x + w - winframe, y);

glTexCoord2f(FB, FC); glvertex2fwin(x + w - winframe, y);
glTexCoord2f(FB, FB); glvertex2fwin(x + w - winframe, y + winframe);
glTexCoord2f(FC, FB); glvertex2fwin(x + w, y + winframe);
glTexCoord2f(FC, FC); glvertex2fwin(x + w, y);

// middle one
glTexCoord2f(F0, FB); glvertex2fwin(x, y + winframe);
glTexCoord2f(F0, FA); glvertex2fwin(x, y + h - winframe);
glTexCoord2f(FA, FA); glvertex2fwin(x + winframe, y + h - winframe);
glTexCoord2f(FA, FB); glvertex2fwin(x + winframe, y + winframe);

glTexCoord2f(FB, FB); glvertex2fwin(x + w - winframe, y + winframe);
glTexCoord2f(FB, FA); glvertex2fwin(x + w - winframe, y + h - winframe);
glTexCoord2f(FC, FA); glvertex2fwin(x + w, y + h - winframe);
glTexCoord2f(FC, FB); glvertex2fwin(x + w, y + winframe);

glTexCoord2f(FA, FB); glvertex2fwin(x + winframe, y + winframe);
glTexCoord2f(FA, FA); glvertex2fwin(x + winframe, y + h - winframe);
glTexCoord2f(FB, FA); glvertex2fwin(x + w - winframe, y + h - winframe);
glTexCoord2f(FB, FB); glvertex2fwin(x + w - winframe, y + winframe);

// bottom one
glTexCoord2f(FB, FA); glvertex2fwin(x + w - winframe, y + h - winframe);
glTexCoord2f(FB, F0); glvertex2fwin(x + w - winframe, y + h);
glTexCoord2f(FC, F0); glvertex2fwin(x + w, y + h);
glTexCoord2f(FC, FA); glvertex2fwin(x + w, y + h - winframe);

glTexCoord2f(F0, FA); glvertex2fwin(x, y + h - winframe);
glTexCoord2f(F0, F0); glvertex2fwin(x, y + h);
glTexCoord2f(FA, F0); glvertex2fwin(x + winframe, y + h);
glTexCoord2f(FA, FA); glvertex2fwin(x + winframe, y + h - winframe);

glTexCoord2f(FA, FA); glvertex2fwin(x + winframe, y + h - winframe);
glTexCoord2f(FA, F0); glvertex2fwin(x + winframe, y + h);
glTexCoord2f(FB, F0); glvertex2fwin(x + w - winframe, y + h);
glTexCoord2f(FB, FA); glvertex2fwin(x + w - winframe, y + h - winframe);

glend;

glFrontFace(GL_CCW);
end;

here are the rest of functions you might need:


// Dwarf with Axe - GAMEDEV forums: 18 July 2002 6:12:57 PM
//
// There have been thousands of posts along the lines of
// "How do I do 2d in OpenGL" to "Duuuhde, I wunt too maek
// a two dee gaem in ohpun jee el; how do eye set uhp two dee???!?"
//
// I have developed a simple, nice, pretty way for all of you to have your 2D fun.

procedure GlEnable2D;
var
vport: array[0..3] of integer;
begin
glGetIntegerv(GL_VIEWPORT, @vPort);

glMatrixMode(GL_PROJECTION);
glPushMatrix;
glLoadIdentity;
glOrtho(0, vPort[2], 0, vPort[3], -1, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix;
glLoadIdentity;
end;

procedure GlDisable2D;
begin
glMatrixMode(GL_PROJECTION);
glPopMatrix;
glMatrixMode(GL_MODELVIEW);
glPopMatrix;
end;

// remap coords to fit windows coordinate system direction
procedure glvertex2fwin(const x, y: single);
begin
glvertex2f(x, engine.win_height - y);
end;

edit: i forgot some stuff:


const
winframe = 64 / 3; // the texture size, if you use bigger change this otherwise it will come up scaled and will look ugly
F0 = 0;
Fa = 1 / 3;
Fb = 2 / 3;
Fc = 1;

basicly, this will draw cool window frames like the ones you saw in hl2 gui.

i'll try to add screenshoots of what this is ;)

PICS:

http://www.gtatools.com/temp/winframea.jpg
http://www.gtatools.com/temp/winframeb.jpg

you can also come up with things like this:
http://www.gtatools.com/temp/example300.jpg

here is how it looks like in my game:
http://www.gtatools.com/temp/winframeinaction.jpg

Robert Kosek
06-02-2005, 02:52 AM
Looks good! I've been scratching my head at this, and you just saved the day! How about some buttons? *hint hint hint*

JernejL
06-02-2005, 02:53 PM
Looks good! I've been scratching my head at this, and you just saved the day! How about some buttons? *hint hint hint*

buttons could be done without textures, like:


procedure drawButton(x, y, w, h: single; focused, pushed: boolean);
begin
resetcolor;
glFrontFace(GL_CW);
glBindTexture(gl_texture_2d, btn.GLID);

glcolor3UB(0, 0, 0);

glLineWidth(1);

// border
glBegin(gl_line_loop);
glvertex2fwin(x, y);
glvertex2fwin(x, y + h);
glvertex2fwin(x + w, y + h);
glvertex2fwin(x + w, y-1);
glend;

glLineWidth(2);

glcolor3UB(255, 255, 255);

// TOP one
glBegin(gl_line_loop);
glvertex2fwin(x+2, y+1);
glvertex2fwin(x+2, y + h-2);
glcolor3UB(128, 128, 128);
glvertex2fwin(x + w-1, y + h-2);
glvertex2fwin(x + w-1, y-1+2);
glend;

glFrontFace(GL_CCW);
end;

this looks quite good, i'll poke around with the button a bit more

noeska
07-02-2005, 06:06 PM
have a look at http://www.noeska.com/dogl/glgui.aspx before reinventing the wheel...

JernejL
07-02-2005, 07:28 PM
have a look at http://www.noeska.com/dogl/glgui.aspx before reinventing the wheel...

you can't stop me!!

*runs towards noeska yelling move! MOVE!!!

:lol:

personally i think taking jan's gui example code for base
for gui interface isn't good as it is real mess.