Game interface panel always on screen?

Started by
16 comments, last by WoolyUK 22 years, 10 months ago
Hi all I cant seem to figure out how to draw a user interface panel on the screen, over the top of the current world view. Even a box would do for now, but I cant figure out how! I must be being very dumb, but how can i draw something, say a box, along the bottom of the screen and always keep it there even when the main game view moves/changes please?? Are there any examples/tutorials/source etc that I could look at? If not comments would be welcomed! Thanks again everyone! Adam
Advertisement
That shouldnt be to hard at all. Just draw your world, then use glLoadIdentity to reset everything, then translate in a unit or two, and draw your panels.
I reccomend switching to ortho for drawing interfaces like doing an overlay. heres what in doing for my space game.

void draw_overlay() {
static float e,w,s;
e += Ship.e/10;
s += Ship.s/10;
w += Ship.w/10;
glMatrixMode ( GL_PROJECTION );
glPushMatrix ( );
glLoadIdentity ( );
glOrtho ( 0.0, ( (double)ScreenWidth ), 0.0, ( (double)ScreenHeight ), -0.0, 0.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
// ------- DRAW FRAME -------
glTranslatef(-0.9,-0.9,0);
glColor3f(0.1,Ship.e/10,0.1);
glRotatef(e,0,0,1);
draw_triangle();
glLoadIdentity();
glTranslatef(-0.7,-0.9,0);
glColor3f(0.1,0.1,Ship.s/10);
glRotatef(s,0,0,1);
draw_triangle();
glLoadIdentity();
glTranslatef(0.7,-0.7,0);
glRotatef(s,0,0,1);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2f(0 ,0.1);
glVertex2f(0.07,0.07);
glVertex2f(0.1 ,0);
glVertex2f(0.07,-0.07);
glVertex2f(0 ,-0.1);
glVertex2f(-0.07,-0.07);
glVertex2f(-0.1,0);
glVertex2f(-0.07,0.07);
glEnd();
glLineWidth(1);
glLoadIdentity();
glTranslatef(-0.5,-0.9,0);
glColor3f(Ship.w/10,0.1,0.1);
glRotatef(w,0,0,1);
draw_triangle();
// ------- DRAW FRAME -------
glMatrixMode ( GL_PROJECTION );
glPopMatrix ( );
glMatrixMode ( GL_MODELVIEW );
}


www.EberKain.comThere it is, Television, Look Listen Kneel Pray.
Yes, basically you will need to draw your box again every frame. Although there is a way you can leave parts of the screen as static it is probably not a great idea.

Seeya
Krippy
Thanks guys, sorted it now. Doh it was easy Shoulda realised myself! Thanks anywyay!

Adam
Hmmmm actually I just tried changing the panel colour cus its being drawn black at the moment, but the panel stays black, and my world goes blue! lol

This is the code im using, after drawing my world:

// Draw interface panel on bottom of screen
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glColor3f(0.0f,0.0f,1.0f);

glBegin(GL_QUADS);

glVertex3f( -2.8f, -1.5f, 0.0f); glVertex3f(-2.8f,-2.1f, 0.0f);
glVertex3f( 2.8f,-2.1f, 0.0f);
glVertex3f( 2.8f,-1.5f, 0.0f);
glEnd();


Howcome the panel is staying black but everything else goes blue please?

Thanks, Adam
1.) add PushMatrix(); before and PopMatrix(); after.
(not sure if this will work)

or

2.) toss in a glColor3f(1.0f, 1.0f, 1.0f); at the end.
that''s what i usually do

Scott

Email
Website

"If you try and don''t succeed, destroy all evidence that you tried."
Thanks for the reply!

I tried glPushMatrix() and glPopMatrix() but they didnt make any difference :-(

Also after adding glColor3f(1.0f,1.0f,1.0f); to the end, my world is now displayed in correct colours so thanks for that!

However, the actual interface panel is still black

Also - If I disable the bits that draw my world using textured quads so that just the interface bar appears, it IS blue then.

But when I uncomment the world drawing sections it becomes black!

Any more ideas please?

Thanks
Adam

Edited by - WoolyUK on June 20, 2001 3:07:23 PM

Edited by - WoolyUK on June 20, 2001 3:11:25 PM
Post your display function in its entirety.

www.EberKain.comThere it is, Television, Look Listen Kneel Pray.
Ok :-)

int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawin
{
glFrontFace(GL_CCW); // Counterclockwise polygons face out
glEnable(GL_CULL_FACE); // Do not try to display the backsides


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

glRotatef(angle,1.0f,-0.0f,0.0f);
glRotatef(360.0f-turn, 0, 1.0f, 0);

GLfloat xtrans = +xpos; // Used For Player Translation On The X Axis
GLfloat ztrans = +zpos;

glTranslatef(xtrans, ytrans,ztrans);




//glEnable(GL_LIGHTING); // Enable Lighting

for (ty = 0; ty < 20; ty++)
{
for (tx = 0; tx < 20; tx++)
{
tile = map[tx][ty];
if ((tile==1) || (tile==2)) {

DrawBlock();
}
else
{
DrawBlank();
}
glTranslatef(2.0f,0.0f,0.0f);
}
glTranslatef(-40.0f,-0.0f,2.0f);

}

// Draw interface panel on bottom of screen
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);


glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_QUADS);

glVertex3f( -2.8f, -1.5f, 0.0f);
glVertex3f(-2.8f,-2.1f, 0.0f);
glVertex3f( 2.8f,-2.1f, 0.0f);
glVertex3f( 2.8f,-1.5f, 0.0f);
glEnd();
glColor3f(1.0f,1.0f,1.0f);

return TRUE; // Keep Going
}

void DrawBlock()
{
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture
glBegin(GL_QUADS);

float pheight = 1.0f;


if (map[tx][ty]==2) {
pheight = 0.0f;
}

// Front Face
if (map[tx][ty+1] != map[tx][ty]) {

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, pheight, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, pheight, 1.0f); // Top Left Of The Texture and Quad
}

if (map[tx][ty-1] != map[tx][ty]) {
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, pheight, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, pheight, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
}
if (map[tx+1][ty] != map[tx][ty]) {
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, pheight, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, pheight, 1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
}
if (map[tx-1][ty] != map[tx][ty]) {
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, pheight, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, pheight, -1.0f); // Top Left Of The Texture and Quad
}
glEnd();

glBindTexture(GL_TEXTURE_2D, texture[1]); // Select Our Texture
glBegin(GL_QUADS);
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, pheight, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, pheight, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, pheight, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, pheight, -1.0f); // Top Right Of The Texture and Quad
// Bottom Face
glEnd();

}

void DrawBlank()
{
glBindTexture(GL_TEXTURE_2D, texture[2]); // Select Our Texture
glBegin(GL_QUADS);
// Bottom Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
// Top Face
//glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
//glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
//glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
//glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glEnd();

}

There it is

This topic is closed to new replies.

Advertisement