Orthographic Projection: I'm really stumped
Well, the 3-d portion of my program now has all its (very)basic parts in good working order.
But now that I''m trying to create a 2D interface display in the same window, I''m getting nowhere fast. I''ve looked at NeHe''s tuts on bitmap fonts and the game tut with orthographic projection and nothing seems to work. Here is the section of code I''ve been trying to work with for my Interface class:
GLvoid CInterface::DrawInterface()
{
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
PrintText(180, 20, "OpenGL Text -%7.2f", txtcnt1);
glPopMatrix();
}
GLvoid CInterface:rintText(GLint x, GLint y, const char *fmt, ...)
{
char text[256];
va_list ap;
if (fmt == NULL)
return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
glTranslated(x,y,0);
glListBase(fontset - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
}
You''ll notice that PrintText() is virtually identical to Nehe''s glPrint(). My thinking was that I could switch projection matrix, do my orthogonal stuff, and then switch back to the original matrix. Like I said, the 3D stuff still works just fine with this code in there, but anything I try to display from within DrawInterface() just doesn''t show up on screen. I also tried drawing just a plain old quad onto the screen but that didn''t work either.
Anyway, if anyone has any ideas or can at least point me in the right direction, I''d appreciate it very much
Anon,
It''s the same as glTranslatef() except with a double precision float. I don''t guess it''s really neccesary over a plain float right now, but Nehe used it so I figured I would too, might need it later
Slayer,
Like I said, I''ve looked over the tuts pretty thoroughly and still can''t figure out what I''m doing wrong. If you could perhaps be more specific I know I''ve overlooked something somewhere, the question is, *exactly* where?
Or do I need to do something with the modelview matrix to get this to work? Guess I''ll try working with that for a while and see what happens.
It''s the same as glTranslatef() except with a double precision float. I don''t guess it''s really neccesary over a plain float right now, but Nehe used it so I figured I would too, might need it later
Slayer,
Like I said, I''ve looked over the tuts pretty thoroughly and still can''t figure out what I''m doing wrong. If you could perhaps be more specific I know I''ve overlooked something somewhere, the question is, *exactly* where?
Or do I need to do something with the modelview matrix to get this to work? Guess I''ll try working with that for a while and see what happens.
i think I know what happened
you tried to change your modelview matrix to ortho. but you have to change the projectionmatrix to it
here are two functions of my source:
NEHE DAVEPERMEN void WINDOW::Set_Perspective(float degrees,float front,float back)
{
//Go to the Projection Matrix to change it and set it to the Identity
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Set the Perspective (and prevent a divide by Zero)
if(res.y!=0)
gluPerspective(degrees,res.x/res.y,front,back);
else
gluPerspective(degrees,res.x/1,front,back);
//Go back to the ModelMatrix to enable Rendering
glMatrixMode(GL_MODELVIEW);
}
NEHE DAVEPERMEN void WINDOW::Set_Paralax(float front,float back)
{
//Go to the Projection Matrix to change it and set it to the Identity
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Set the Matrix to 2D-Projection with (0,0) in the middle of screen
glOrtho(-res.x/2,res.x/2,-res.y/2,res.y/2,front,back);
//Go back to the ModelMatrix to enable Rendering
glMatrixMode(GL_MODELVIEW);
}
I think that should show you, what I mean..
we wanna play, not watch the pictures
you tried to change your modelview matrix to ortho. but you have to change the projectionmatrix to it
here are two functions of my source:
NEHE DAVEPERMEN void WINDOW::Set_Perspective(float degrees,float front,float back)
{
//Go to the Projection Matrix to change it and set it to the Identity
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Set the Perspective (and prevent a divide by Zero)
if(res.y!=0)
gluPerspective(degrees,res.x/res.y,front,back);
else
gluPerspective(degrees,res.x/1,front,back);
//Go back to the ModelMatrix to enable Rendering
glMatrixMode(GL_MODELVIEW);
}
NEHE DAVEPERMEN void WINDOW::Set_Paralax(float front,float back)
{
//Go to the Projection Matrix to change it and set it to the Identity
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Set the Matrix to 2D-Projection with (0,0) in the middle of screen
glOrtho(-res.x/2,res.x/2,-res.y/2,res.y/2,front,back);
//Go back to the ModelMatrix to enable Rendering
glMatrixMode(GL_MODELVIEW);
}
I think that should show you, what I mean..
we wanna play, not watch the pictures
your function then has to look like this:
GLvoid CInterface::DrawInterface()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
PrintText(180, 20, "OpenGL Text -%7.2f", txtcnt1);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
we wanna play, not watch the pictures
GLvoid CInterface::DrawInterface()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
PrintText(180, 20, "OpenGL Text -%7.2f", txtcnt1);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
we wanna play, not watch the pictures
Daverpermen,
Thank you very much for that info. I really appreciate a detailed response like that:-) It did clear up something I had read in the OpenGL Programming Guide which I wasn''t sure about.
Unfortunately, my text still isn''t displaying even though all my 3D stuff continues to render normally. Somehow, I am starting to suspect that the problem is somewhere in my object based framework.
Anyway, I think I am just going to go home and do some reading in the red book for the rest of the day, try to not sweat the details just yet. It''s obvious that I need to reread chapter 3 on viewing anyway. I''m sure the answer will come in time. And knowing me, it will probably be something silly that I forgot somewhere
Thanks again for your help
Thank you very much for that info. I really appreciate a detailed response like that:-) It did clear up something I had read in the OpenGL Programming Guide which I wasn''t sure about.
Unfortunately, my text still isn''t displaying even though all my 3D stuff continues to render normally. Somehow, I am starting to suspect that the problem is somewhere in my object based framework.
Anyway, I think I am just going to go home and do some reading in the red book for the rest of the day, try to not sweat the details just yet. It''s obvious that I need to reread chapter 3 on viewing anyway. I''m sure the answer will come in time. And knowing me, it will probably be something silly that I forgot somewhere
Thanks again for your help
when you cant solve the problem, you probably could send me your source, and I take a look at it..
i had problems implementeing print, too (and for a long time) and from one moment, to the other, it worked.. and now, it works everytime
and, when it really doesn''t work, i perhaps could give you a little present (*GRIIINNNSS*)
ps: the GRINS means a big
pps: a VERY BIG
we wanna play, not watch the pictures
i had problems implementeing print, too (and for a long time) and from one moment, to the other, it worked.. and now, it works everytime
and, when it really doesn''t work, i perhaps could give you a little present (*GRIIINNNSS*)
ps: the GRINS means a big
pps: a VERY BIG
we wanna play, not watch the pictures
glTranslated is the double number version of glTranslatef
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80, winWidth/winHeight, 5, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
gluLookAt(cameraPOS[0],cameraPOS[1],cameraPOS[2], cameraDIR[0],cameraDIR[1],cameraDIR[2], 0,1,0);
// draw 3d stuff
glPopMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,winWidth,0,winHeight,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw 2d stuff
hmmm a few to many glLoadIdentity()''s in there
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80, winWidth/winHeight, 5, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
gluLookAt(cameraPOS[0],cameraPOS[1],cameraPOS[2], cameraDIR[0],cameraDIR[1],cameraDIR[2], 0,1,0);
// draw 3d stuff
glPopMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,winWidth,0,winHeight,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw 2d stuff
hmmm a few to many glLoadIdentity()''s in there
ok, I think I know the problem:
CInterface uses, for the textcreation, gl-functions (wglTextfromBmp or something like this)in the constructor, and your MyInterface is global, means, the constuctor is called at the start of the program. But then you havent created yet your opengl-rendering-context, so wglTexblablah cant do anything, and so you dont create text, and then your Print cant work, too
we wanna play, not watch the pictures
CInterface uses, for the textcreation, gl-functions (wglTextfromBmp or something like this)in the constructor, and your MyInterface is global, means, the constuctor is called at the start of the program. But then you havent created yet your opengl-rendering-context, so wglTexblablah cant do anything, and so you dont create text, and then your Print cant work, too
we wanna play, not watch the pictures
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement