View Full Version : 2D pictures
05-21-2000, 03:38 PM
I am having a lot of trouble getting .bmp files to show up as regular pictures (not textures). I have a function that loads the .bmp file, which I have tested, and it works fine. But when I display the pixmap, nothing ever shows. Here's my code for drawing the bitmap...
void Draw2d::drawBitmap( unsigned int id, int x, int y )
glRasterPos2i( x, y );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glDrawPixels( bitmaps[id].width, bitmaps[id].height, GL_BGR_EXT, GL_UNSIGNED_BYTE, bitmaps[id].data );
bitmaps[id] is the class that holds the bitmap data. I only am using id = 0 right now, and x and y are both 100. All the data in the bitmaps class is the way it should be. The bitmaps.data is directly taken from a Windows bitmap file 24-bit, the width and height fields are both 64. I am just learning how to setup pictures, so any help would be greatly appreciated. I know that the renderer itself works, because i have 3d objects already in the scene. Thanks!
Are you sure that x= 100 and y =100 is on your screen?
If you use gluPerspective and have a FOV of let's say 60 degrees and a zNear of 1.0 and a ration of 1, your screen is :
left = -1.73, right =1.73, top = 1.73, bottom = -1.73
05-21-2000, 07:29 PM
I see your point, but when I use glRasterPos2i( x, y ), don't x and y have to be integers? Do I use screen coordinates or world coordinates? I have tried x=0, and y=0 as well but have not had success.
glRasterPos2i is the integer version, but you can use the float version for more precision glRasterPos2f, you can also use glRasterPos3* to set the z coordinates.
It is in world coordinate, so it is transformed like any other vertex.
But I know what the problem is now(apart that 100X100 is still out of the screen but we will fix that):
If you use glRaster2*, then the z parameter = 0. But your zNear is always greater than 0 so the bitmap will never show. So what you can do is set a Z coordinate directly. You still have to make sure that the point will be in view after transform if you want it to be drawn.
A simple way is before calling glRasterPos*, change your projection to orthogonal and set a width and height that is bigger than 100(to make you image appear) and still use glRasterPos2i, because for ortho, z=0 is right in front of the viewer.
05-22-2000, 01:26 PM
I fixed it! I have a bunch of 3d objects and transormations. I put this code after all of it:
glMatrixMode( GL_PROJECTION );
glOrtho( 0, 640, 480, 0, 0, 100 );
i = draw2d.loadBitmap( "images/Image1.bmp" );
draw2d.drawBitmap( i, 0, 64 );
draw2d.freeBitmap( i );
and i used glRasterPos2i().
Strangely when though, when I use GL_MODELVIEW instead of GL_PROJECTION, it doesn't work. Any ideas on why this is so? As you can see I'm still trying to get a good grip on the whole 3D-matrix idea =)
Thanx again for all you help!
opengl 1.1 has three matrices: projection, modelview and texture.
since the only way to modify a matrix is via the matrix functions glRotate, glTranslate, glScale, glMultMatrix... and that functions don't have a parameter to tell gl wich matrix is to be modified, you set the active matrix, ie the matrix you wish to modify, by calling glMatrixMode.
glOrtho, as well gluOrtho2D, simply generate the matrix and multiply it with the current active matrix, that's why the thing won't work if you don't call glMatrixMode(GL_PROJECTION) before it.
[This message has been edited by dmy (edited 05-23-2000).]
05-24-2000, 04:59 PM
Thanks for all your help, but I have a new question.
I want to get a section of a source bitmap and output it onto the the screen in a certain spot...How do I specify the width of the section of the source image?
glRasterPos2i( x+offset, y );
to specify the coords of the destination image, and
glPixelStorei( GL_UNPACK_SKIP_PIXELS, fontface[fontNum].widthData[character] );
to specify the coords of the source image (y coords are always the same), and
glDrawPixels( fontface[fontNum].width, fontface[fontNum].height, GL_RGBA, GL_UNSIGNED_BYTE, fontface[fontNum].imageData );
which draws it. The fontface[fontNum].width parameter is the width of the entire source image (or at least I think so, correct me if I am wrong)
I don't see how I can specify the width of the section of the source image I want to copy. Do I always have to copy the entire source image?
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.