View Full Version : print a logo to the screen

ladybug

03-08-2001, 12:41 PM

I am trying to print a logo on a window. It is a 3-d window (the mouse can move the view point all around the objects). The other labels I have in the window are made to move with the objects. Now, when I am trying to place a logo in the bottom corner, I cannot get it to translate to its position.

I have tried: glrasterpos2i( , ) and gltranslatef( ) before and after the print statement.

It seems so obvious, but I cannot get the logo to move from the center of the screen. Any help is appreciate. http://www.opengl.org/discussion_boards/ubb/redface.gif

hello,

the raster position is also affected by the curretn transformation matrix and the projection matrix (even though raster positions are intuitively 2D entities).

oh, and if glrasterpos* falls outside the viewport, then its new position isn't set. so, check the following:

- make sure you know what your projection matrix is doing

- make sure you have set up your desired transform matrix

> when in doubt (and in *serious* bug-fix mode), try multiplying out your projection and transform matricies with the desired raster pos, and check that the output you're getting makes sense to you

cheers,

John

Tim Stirling

03-10-2001, 12:45 AM

Load an identity matrix (glLoadIdentity() http://www.opengl.org/discussion_boards/ubb/wink.gif and then translate out a little from the screen and then use the glRasterPos*() function. Otherwise it is still affected by translations and rotations which is strange. This is what I have to do to get text to display correctly.

The best way to print something (2D logo, text ... ) at a given position on the screen is to reset your projection matrix to an orthogonal projection w/ one unit per pixel.

This done, you can work in screen coordinates

You can do it like this:

GLint viewport[4];

GLint saved_matrix_mode;

// Get the viewport

glGetIntegerv(GL_VIEWPORT, viewport);

// Save current matrix mode

glGetIntegerv(GL_MATRIX_MODE, &saved_matrix_mode);

// Save current modelview matrix

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

// Load identity matrix for modelview transformation

glLoadIdentity();

// Save current projection matrix

glMatrixMode(GL_PROJECTION);

glPushMatrix();

// Load identity matrix for viewing projection

glLoadIdentity();

// Set new projection matrix (orthogonal)

gluOrtho2D(0.0, (GLfloat) viewport[2], 0.0, (GLfloat) viewport[3]);

// Set raster position in screen coordinates

glRasterPos2i(Origin.x, Origin.y);

// Draw your logo

glDrawPixels(width, height, format, GL_UNSIGNED_BYTE, image_buffer);

// Restore the matrices

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

glPopMatrix();

// Restore matrix mode

glMatrixMode(saved_matrix_mode);

Edit: A quad with a nice blended texture (w/ an alpha channel, loaded from a TGA file) is much better than glDrawPixels because it is much faster with hardware acceleration.

You can specify the coordinates of the vertices of your quad as 2 integers (x, y) representing screen coordinates and don't need to specify the raster position any more.

[This message has been edited by Moz (edited 03-10-2001).]

[This message has been edited by Moz (edited 03-11-2001).]

Tim Stirling

03-11-2001, 12:52 AM

Moz for that type of method you don't have to save the matrix, just push and then pop the matrix back.

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix

glPushMatrix(); // Store The Projection Matrix

glLoadIdentity(); // Reset The Projection Matrix

glOrtho(0,640,0,480,-100,100); // Set Up An Ortho Screen

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

glPushMatrix(); // Store The Modelview Matrix

glLoadIdentity(); // Reset The Modelview Matrix

glTranslated(x,y,0);

// draw some stuff (blended, textured, alpha tested quad etc.)

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix

glPopMatrix(); // Restore The Old Projection Matrix

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

glPopMatrix();

This should be faster than saving a matix (maybe not that much) but makes for better code.

Tim

Tim,

look again, I don't save the matrices, I push/pop the modelview and projection matrices. What I save is the matrix mode (It's most likely to be GL_MODELVIEW so you can skip the calls to glGetIntegerv(GL_MATRIX_MODE, &saved_matrix_mode) and glMatrixMode(saved_matrix_mode)).

Deiussum

03-11-2001, 07:39 AM

One thing you did forget to do was a LoadIdentity before you call gluOrtho2d

glPushMatrix(); // Load new projection matrix (orthogonal)

gluOrtho2D(0.0, (GLfloat) viewport[2], 0.0, (GLfloat) viewport[3]);

If you don't put glLoadIdentity() between those two calls, you will be multiplying the current matrix with the results of gluOrtho2d, and probably won't get what you want. http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Deiussum (edited 03-11-2001).]

Good point Deiussum http://www.opengl.org/discussion_boards/ubb/biggrin.gif!

I corrected it to make the code right.

Thanx for mentionning that.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.