Game Development Community

drawing bitmaps onto the screen

by Stefan · in Torque Game Engine · 11/24/2001 (9:43 am) · 7 replies

Hello,
I have already tried this by editing game.cc, function:
void GameRenderFilters(const CameraQuery& camq)
I added the following, trying to paint a bitmap constantly onto the screen.
TextureHandle *mynvpic = new TextureHandle("data/special/mysqnv", BitmapTexture, true);
glBindTexture(GL_TEXTURE_2D, mynvpic->getGLName()); 

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 1, 1, 0.5);
glBegin(GL_TRIANGLE_FAN);
		         
glTexCoord2f(-1, 1);
glVertex2f(-1, 1);
   
glTexCoord2f(1, 1);
glVertex2f(1, 1);
   
glTexCoord2f(1, -1);
glVertex2f(1, -1);

glTexCoord2f(-1, -1);
glVertex2f(-1, -1);
glEnd();

glDisable(GL_BLEND);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBlendFunc(GL_ONE, GL_ZERO);
glDepthMask(GL_TRUE);
and so on....
When I compile this and run the program, I get a grey layer on my screen, but no signs of the bitmap I made. I also don't get any error messages. I suppose that those lines with the new TextureHandle and GLBindTexture don't work. Please help me! I'm really stuck at this point :(

#1
11/24/2001 (1:17 pm)
im assuming you dont want to tile your bitmap. the s,t coords of the texture range from 0 to 1, not -1 to 1 like your doing in your gltexcoord2f. if you wanted to tile, youd have to set tiling then make it go from 0 to however many coords you want.

ala:

TextureHandle *mynvpic = new TextureHandle("data/special/mysqnv", BitmapTexture, true);
glBindTexture(GL_TEXTURE_2D, mynvpic->getGLName());

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 1, 1, 0.5);
glBegin(GL_TRIANGLE_FAN);

glTexCoord2f(0, 1);//upper left coord
glVertex2f(-1, 1);

glTexCoord2f(1, 1);//upper right coord
glVertex2f(1, 1);

glTexCoord2f(1, 0);//bottom left coord
glVertex2f(1, -1);

glTexCoord2f(0, 0);//bottom right coord
glVertex2f(-1, -1);
glEnd();

glDisable(GL_BLEND);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBlendFunc(GL_ONE, GL_ZERO);
glDepthMask(GL_TRUE);



i dont know much else about what you are doing, xcept you want it to blend half with your background and half your bitmap. your probably better off using the primative gl_polygon than gl_triangle_fan, but if it works, dont break it. If that doesnt work, reply and ill take a look...
Ryan

edit: also, you should specify the coords in CCW. the default is ccw, and most likely you are looking at the back face yet texturing the front face.
#2
11/25/2001 (12:27 pm)
ok thanks for that suggestion. I did what you said but it's still all grey, like it didn't load any image. I also modified my picture and made it 256x256 in size, but that didn't help.
I think the biggest problem right now is loading the image. I think that method with new TextureHandle doesn't work. Once I had a TextureObject with a loaded image, I could also use those basic 2D functions for painting an image on the screen that are located in dgl.cc. But I don't know how to make such a TextureObject or TextureHandle.
#3
11/26/2001 (8:49 am)
The new TextureHandle() call should be working. I believe that is the correct way to load textures. You might want to trace through it to where the file is actually read to see what's happening.
#4
11/27/2001 (6:00 am)
ok, I may have found the bug: I wanted to change the footstep.png for fun... I just made it a little bit bigger but it looked almost the same. I saved it and when I ran the engine, the footsteps were totally white boxes, and not transparent. Now my idea is, that for some reason the same thing happens with my png file that I want to paint onto the screen and that it's just totally white. This would explain why I get a grey layer on the screen.

So, what could I have done wrong when saving the .png file?? Does it have to be interlaced or not? Do I have to add anything? Should it be RGB??

Maybe when I get the footsteps right I can get the other thing working easily.....
#5
11/27/2001 (7:15 am)
is the new enlarged footprint pic a power of 2?
#6
11/28/2001 (5:26 am)
nope, is that a must?
#7
11/28/2001 (6:17 am)
ok I made the footprint's width a height of power 2, and the footprints worked. But this doesn't solve my main problem. I have made a 256x256 png file for testing, and it's just grey. I also made it transparent at some spots but you can see no difference on the screen. So, please help!