seethrough texture help

Apr 23, 2012 at 11:36pm
Does anyone know if it's possible to make parts of a bitmap texture seethrough? Like, if a specific part of the bitmap is colored with a certain color, it's seethrough when it's displayed.Here's what I use to load textures so far.


P.S. I only included what I thought was relevant to the question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Gluint texture[100];
int LoadGLTextures(int ID)     
{
        texture[ID] = SOIL_load_OGL_texture("game_textures/buy_screen/egg_fef.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
	glBindTexture(GL_TEXTURE_2D, texture[ID]);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	return true;                                       
}
void drawTexture(int id, float x, float y, float z, float scale)
{
	LoadGLTextures(id);
	glBindTexture(GL_TEXTURE_2D, texture[id]);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale+x, -scale+y,  z);
	glTexCoord2f(1.0f, 0.0f); glVertex3f( scale+x, -scale+y,  z);
	glTexCoord2f(1.0f, 1.0f); glVertex3f( scale+x,  scale+y,  z);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale+x,  scale+y,  z);
	glEnd();
}

//......
//in the draw function
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();          
        glColor3d(light,light,light);
	drawTexture(48,  -.86,  1.44,   -2.9995, .64);
        //bluh bluh, other code

        glutSetWindow(1);
	resize(600,600);
	glutPostRedisplay();
	glutSwapBuffers(); //352, 234


So what do I need to change to make parts of the image seethrough? thanks!
Apr 24, 2012 at 2:01am
I'm not familiar with how to use SOIL, but so long as it provides a way of reading/writing pixel values in textures, this is an easy problem to solve. When a texture is loaded, read all of its pixels values, and if their equal to the color that specifies transparency, change the value to a transparent one.
Apr 24, 2012 at 7:56pm
Well, that's what I had in mind, but how would I do that..? How do I loop through each and every pixel in a texture?
Apr 24, 2012 at 10:20pm
That depends on how you access image info (width/height) and pixel data using SOIL. I have never used SOIL, so I'm not sure how its done, try checking the docs for it.
Apr 24, 2012 at 10:23pm
The easiest way is to store the transparent color in the image itself.

Convert the .bmp to a .png and set the desired color to be transparent in the .png (you can do this with any halfway decent image conversion program, there are many free ones available. read: MS Paint doesn't count).

Any decent image loading library will preserve transparency/alpha information and apply it to the texture.
Topic archived. No new replies allowed.