Archived

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

Game interface panel always on screen?

This topic is 6023 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
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
I found this cool article on GUI development:

http://www.gamedev.net/reference/programming/features/gui/

Although I haven''t read it, I plan to because I have pretty much the same question as you. The GUI stuff uses DirectX, but I think thats only for like DirectInput and stuff, not any graphics. I could be wrong, but I don''t think it would be hard to port the GUI graphics to OpenGL. The DirectInput stuff, on the other hand, is pretty much all you can use.

--SK

Share this post


Link to post
Share on other sites
But when I disable the world drawing bits and draw just the panel it is blue then - even with the current culling settings.

Could it still be that?

Adam

Share this post


Link to post
Share on other sites
Not sure if this is the problem or not, but normally you want to disable texturing before you draw something that you want to be a solid color. Otherwise the last texture that was bound will be used when you draw, without any red or green components since your only non-zero color channel is set to blue.

add glDisable( GL_TEXTURE_2D ); before you draw your box and then:

glFlush();
glEnable( GL_TEXTURE_2D ); after you draw it.

if you don''t use glFlush() first then it might ignore when you disable texturing because you re-enabled it before the buffer is sent to the video card.

Hope this helps.

Seeya
Krippy

Share this post


Link to post
Share on other sites
YAY!!

Krippy saves the day for me! (again)

Thanks dude, U have helped me about 5 times now! lol

You rock! And so does everyone else in this thread who helped me!

Thanks again!

Adam

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
... or my personal favorite way, disable depth test and then draw it!
I would think that would be faster than doing translations... even if the translations came in at 0 cost, then the fact that it is still doing depth testing against other polygons probably comes in at a cost.
Disabling depth testing ought to be a fairly cheap state change since it probably only toggles a variable which determines whether or not it runs a check on the depths each time it draws!

Share this post


Link to post
Share on other sites
Hmmm... Well turning off depth testing is always a good idea, but you still need to translate or you will need to do some expensive calculations to find the correct dimensions that you need to make your box for it to always look right.

And you still need to disable texture mapping (not sure if that was relevant to what you were trying to say or not... lol).

But the reason for turning off depth testing is not for speed concerns, todays hardware is real efficient on depth testing, but if you don''t and you get close to other objects they might draw over your interface.


Seeya
Krippy

Share this post


Link to post
Share on other sites