Skip to main content
GameDev.net gamedev.net
🔒 Locked

texturing.....

Started by ff8 Jul 4, 2004 at 5:34 PM 3 replies 400+ views
Original Post
ff8
ff8
i have .bmp file for paper tree (256*256) its background is black i want to make the alpha for background 0 (just the background except the paper tree) second ... i wnat to make frame per second for my project (i am using glut for the window) bye! ff8
soconne
soconne
For your first question:
Let's say you loaded your bitmap already into an array
unsigned char *bmpData = new unsigned char[Size*Size*3];

then what you want to do now is create another array with the alpha channel, copy the pixel data, and then for each pixel that is black, set the alpha channel to 0.

unsigned char *newData = new unsigned char[Size*Size*4];

for(int i=0; i < Size; i++)
for(int j=0; j < Size; j++) {
newData[(i*Size+j)*4+0] = bmpData[(i*Size+j)*3+0];
newData[(i*Size+j)*4+1] = bmpData[(i*Size+j)*3+1];
newData[(i*Size+j)*4+2] = bmpData[(i*Size+j)*3+2];

if(bmpData[(i*Size+j)*3+0] == 0 && bmpData[(i*Size+j)*3+1] == 0) && bmpData[(i*Size+j)*3+2] == 0)
newData[(i*Size+j)*4+3] = 0;
else
newData[(i*Size+j)*4+3] = 255;
}

Then in OpenGL just call the following functions:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NEQUAL, 0);

Also, when you create the OpenGL Texture Object, make sure you pass GL_RGBA to glTexParameteri and not GL_RGB



For the frames per second do the following in your main loop

// declare before main loop
int curTick=GetTickCount(), startTick=curTick;
int frames=0;

//main loop
while(1) {

frames++;
curTick=GetTickCount();
if(curTick-startTick > 1000) {
startTick=curTick;
SetWindowText("Frames Per Second=" + frames);
frames=0;
}
}



And that should work :-)
Author Freeworld3Dhttp://www.freeworld3d.org
ff8
ff8
tx alot for answering me :)
but in second i am using glut for the window project not windows.h
soconne
soconne
oh it doesn't matter, you can still use the GetTickCount function. It shouldn't matter. Just include windows.h in your project.

But if you really don't want to use it, you can also use glut's glutTimerFunc().

The code would pretty much be the same, increment frame++ in your main loop. But instead of displaying the frames per second in your main loop, do it inside the glutTimerFunc and have it execute every second.

Here's a FAQ on it http://www.opengl.org/resources/faq/technical/glut.htm
Author Freeworld3Dhttp://www.freeworld3d.org
ff8
ff8
thank you :)
bye!
ff8

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.