Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

WoolyUK

Game interface panel always on screen?

This topic is 6238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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 );
}


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!