A few questions

Moderator
Posts: 133
Joined: 2008.05
Post: #1
When I push/pop a matrix, what kind of things are affected by this? For example, I know that translate and rotate calls are. But what about calls to glEnable and glDisable? If I enable blending in the modelview matrix, and then pop that one off is blending still enabled?

Also, I'm currently having a problem in my code, but am too frustrated at 3am to fix it. Here's the deal, I set up the camera, do my "3d stuff" and draw all that. Then I switch to ortho mode to draw stuff that will go directly onto the screen(windows and widgets and wooley mammoths...) and not affected by the z axis. The problem with this is that when I switch to orthographic with this code:
Code:
glViewport(0,0,screenResolution.h,screenResolution.v);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0.0f,screenResolution.h,screenResolution.v,0.0f,-1.0f,1.0f);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
My alpha mask basically stops working, it draws the entire thing. I believe because it doesn't 'remember' the old stuff I drew, so it can't make anything transparent if that makes any sense. Would that situation be resolved by not resetting the modelview matrix?

Also, what's the deal with glRasterPos2d. From my limited understanding, it's like calling glVertex2f without projecting it anywhere. However, when I call it in projection mode I don't really get the same results. For example, I have a piece of code that goes something like this:

(switch to ortho mode)

Code:
void TextEngine::DrawText2D(char* string, double* point)
{
    glPushMatrix();
        glLoadIdentity();
        glRasterPos2d(point[0],point[1]);
        glColor3f(TextEngine::color[0],TextEngine::color[1],TextEngine::color[2]);
        DrawCStringGL(string, !usingLarge?(TextEngine::smallText):(TextEngine::largeText));
        glColor3f(1,1,1);
    glPopMatrix();
}


Where drawcstringgl is just calling a display list, it's code provided by apple in aglString.cpp.

Anyway, that's just dandy, trying it while in projection mode means either one of two things: I can't see it, or it scrolls across the screen real fast.

Well, that's all I have. If it's unclear, let me know and I can assist you in assisting me and we can all be assisters.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
LongJumper Wrote:When I push/pop a matrix, what kind of things are affected by this? For example, I know that translate and rotate calls are. But what about calls to glEnable and glDisable? If I enable blending in the modelview matrix, and then pop that one off is blending still enabled?

Only transformations are stored in matrices. This includes translation, rotation, scaling, and skewing. Enable states have separate push/pop functions: glPushAttrib() and glPopAttrib().

LongJumper Wrote:Also, I'm currently having a problem in my code, but am too frustrated at 3am to fix it. Here's the deal, I set up the camera, do my "3d stuff" and draw all that. Then I switch to ortho mode to draw stuff that will go directly onto the screen(windows and widgets and wooley mammoths...) and not affected by the z axis. The problem with this is that when I switch to orthographic with this code:
Code:
glViewport(0,0,screenResolution.h,screenResolution.v);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0.0f,screenResolution.h,screenResolution.v,0.0f,-1.0f,1.0f);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
My alpha mask basically stops working, it draws the entire thing. I believe because it doesn't 'remember' the old stuff I drew, so it can't make anything transparent if that makes any sense. Would that situation be resolved by not resetting the modelview matrix?

OpenGL won't just "forget" that you drew something unless you call glClear(GL_COLOR_BUFFER_BIT). The contents of the framebuffer don't have anything directly to do with the modelview or projection matrices.

I'm not entirely sure what you're describing here... Screenshots would be helpful.

LongJumper Wrote:Also, what's the deal with glRasterPos2d. From my limited understanding, it's like calling glVertex2f without projecting it anywhere. However, when I call it in projection mode I don't really get the same results. For example, I have a piece of code that goes something like this:

(switch to ortho mode)

Code:
void TextEngine::DrawText2D(char* string, double* point)
{
    glPushMatrix();
        glLoadIdentity();
        glRasterPos2d(point[0],point[1]);
        glColor3f(TextEngine::color[0],TextEngine::color[1],TextEngine::color[2]);
        DrawCStringGL(string, !usingLarge?(TextEngine::smallText):(TextEngine::largeText));
        glColor3f(1,1,1);
    glPopMatrix();
}


Where drawcstringgl is just calling a display list, it's code provided by apple in aglString.cpp.

Anyway, that's just dandy, trying it while in projection mode means either one of two things: I can't see it, or it scrolls across the screen real fast.

I think I remember reading in the Red book the glRasterPos*() typically shouldn't be used in projection mode. I don't really know what happens if you do, though...

Hope this helps.

Alex Diener
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #3
LongJumper Wrote:My alpha mask basically stops working, it draws the entire thing. I believe because it doesn't 'remember' the old stuff I drew, so it can't make anything transparent if that makes any sense.
I bet you're using blending and the depth buffer at the same time. Since you're presumably drawing a 2D overlay over a 3D scene, your overlay doesn't really need to use the depth buffer. In that case, turn it off while you draw the overlay.

If you really need to draw depth buffered shapes in the overlay, you should clear the depth buffer between drawing your 3D and 2D objects so that you can start again with a clean slate. You'd probably also need to sort your blended objects into furthest-to-nearest order.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Post Reply