Advertisement

Problems implementing a console...

Started by November 07, 2000 06:40 PM
5 comments, last by JimmyP 24 years ago
Alright...basically all the console is is a quad with a texture on it where you can type commands etc.I have all of this but I seem to have problems placing the quad onscreen.The problem is tha world coords aren''t constant due to continouus translations/rotations so I have to use window coords(aka pixels etc.).To translate window coords to world coords I use gluUnProject().This seems to work fine for a more or less static screen but when I use glRotatef() to rotate the screen the console seems to flicker(i.e. I can see many polys inside the quad appear and disappear rapidly).Can someone explain this or give an other solution?Thanx -=Jimmy=-
-=Jimmy=-
set the projection matrix to a perspective projection (or whatever you want)
render your world,
change the projection matrix to an ortho projection
render the console
loop from the beginning
Advertisement
Have you tried glPushMatrix();?

So pretty much call glPushMatrix();
then glPopMatrix();
So there other translations won''t affect you quad.

I tHinK that''s what you are looking for.
Anybody??
I have tried using an orthographic projection but I had some problems and I so I tried glUnProject.I guess I can get it to work but will this solve my flickering problem?Also won''t I need glUnProject anyway to render the console to a specific wiondow(pixel) location?

As for glushMatrix().I don''t think it''ll work...and I need to make the quad 512*256 pixels and place it on the lower left corner of the window so I need access to pixel coords.

Thanx again and keep posting...
-=Jimmy=-
I tried using ortho proj. but with no success.I''m posting the code below:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,.1,100.0);

glMatrixMode(GL_MODELVIEW);
glGetDoublev(GL_MODELVIEW_MATRIX, modelmatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
glGetIntegerv(GL_VIEWPORT, vport);

gluUnProject(0.0f,0.0f,0.0f,modelmatrix,projmatrix,vport,&objx,&objy,&objz);
glBindTexture(GL_TEXTURE_2D, skin->texID);
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex3d(objx,objy,objz);
gluUnProject(.0f,256.0f,0.0f,modelmatrix,projmatrix,vport,&objx,&objy,&objz);
glTexCoord2i(0,1);
glVertex3d(objx,objy,objz);
gluUnProject(512.0f,256.0f,0.0f,modelmatrix,projmatrix,vport,&objx,&objy,&objz);
glTexCoord2i(1,1);
glVertex3d(objx,objy,objz);
gluUnProject(512.0f,.0f,0.0f,modelmatrix,projmatrix,vport,&objx,&objy,&objz);
glTexCoord2i(1,0);
glVertex3d(objx,objy,objz);
glEnd();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);


This is pretty much the code tha renders the consle.There''s also some code to display text and animate it but that''s of no relvance.I hope the code will be readable but I doubt it....

-=Jimmy=-
-=Jimmy=-
Anon. is right... the best way to do this is to render your world with your perspective projection, then change to a orthographic projection for your console, rinse, and repeat.

A quasi-code example:
    void Render(){    glClear(...)  //clear any buffers or whatever    glLoadIdentity();  //I assume modelview is current    // do all your funky world drawing here...    if( consoleShowing )    {        glMatrixMode(GL_PROJECTION);        glPushMatrix();  //save your world projection        glLoadIdentity();        // Now set a nice 2D projection...        glOrtho(0, screenResX, screenResY, 0, -1, 1);        // clear up transforms for when you draw console...        glMatrixMode(GL_MODELVIEW);        glPushMatrix();        glLoadIdentity();        // do your console stuff here...        // restore everything, ready for next world frame...        glPopMatrix();   // restore modelview transforms        glMatrixMode(GL_PROJECTION);        glPopMatrix();   // restore previous projection        glMatrixMode(GL_MODELVIEW);  // I always default to modelview...    }    glFlush();    SwapBuffers(hDC); // or whatever}    

Now, the lovliness of this is that you can set up your Ortho projection so that it imitates addressing at a pixel level by making its dimensions that of the screen/window width and height... so calls like glTranslatef(200, 300, 0); will actually go to pixel 200,300... ahh, the magic of it all

Hope that helped you understand


NOTE: I may have mucked up the order of the params in the glOrtho(...) call (i''m kinda in a hurry), but you get the idea...


------------------------------------------------------
"You need a weapon. Look around you... can you construct some sort of rudimentary lathe?"
- Guy Fleegman, Security Officer, NSEA Protector
Advertisement
I can''t thank you enough.seems like this flickering problem was related to gluUnProject()(must have been buggy).Anyway I have tried your way and I get only half the console but that''s propably no problem...It doesn''t flicker anymore and it is much smoother.Thanx again to anyone that posted.

BTW how do you put your code in this white frame?

-=Jimmy=-
-=Jimmy=-

This topic is closed to new replies.

Advertisement