Jump to content
  • Advertisement
Sign in to follow this  
tomsh

texture, background delete

This topic is 2553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey.

I tried to delete the background of texture,


glEnable (GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBegin(GL_QUADS); //draw...
glTexCoord2d(1.0f,1.0f);glVertex3f( xP, yP2, 0);
glTexCoord2d(0.0f,1.0f);glVertex3f( xP2, yP2, 0);
glTexCoord2d(0.0f,0.0f);glVertex3f( xP2, yP, 0);
glTexCoord2d(1.0f,0.0f);glVertex3f( xP, yP, 0);
glEnd();



So it deleted it... but it draws other background inplace...
It draw the glClearColor
glClearColor(0.f, 1.f, 0.f, 0.1f);

but I want it [font=Arial,]transparent.[/font]
[font=Arial,]
[/font]
[font=Arial,]44130636.png
[/font]
[font=Arial,]You see the green background they have?[/font]

[font="Arial,"][size=2]
[/font]

Share this post


Link to post
Share on other sites
Advertisement

Hey.

I tried to delete the background of texture,


glEnable (GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBegin(GL_QUADS); //draw...
glTexCoord2d(1.0f,1.0f);glVertex3f( xP, yP2, 0);
glTexCoord2d(0.0f,1.0f);glVertex3f( xP2, yP2, 0);
glTexCoord2d(0.0f,0.0f);glVertex3f( xP2, yP, 0);
glTexCoord2d(1.0f,0.0f);glVertex3f( xP, yP, 0);
glEnd();



So it deleted it... but it draws other background inplace...
It draw the glClearColor
glClearColor(0.f, 1.f, 0.f, 0.1f);

but I want it [font="Arial,"]transparent.[/font]
[font="Arial,"]
[/font]
[font="Arial,"]44130636.png
[/font]
[font="Arial,"]You see the green background they have?[/font]

[font="Arial,"] [/font]



Are your game-play objects use 32-bit textures? Looks like they haven't alpha channels...

Share this post


Link to post
Share on other sites
I think I didn't understand what you said.
the textures are png, I loaded them with sfml.

texture[fNum].LoadFromFile(fName)

Share this post


Link to post
Share on other sites

I think I didn't understand what you said.
the textures are png, I loaded them with sfml.

texture[fNum].LoadFromFile(fName)

Did you checked alpha (mask) channels of them? (Better if you would upload this texture).

Share this post


Link to post
Share on other sites

picxj.png

this is the picture


Texture is set correct (it contains mask channel which have visible and invisible (intensity) pixels).


OpenGL code which you putted in is correct too (for transparent effect).

I think bug is in another place.




Just a warning message: you calling glTexCoord2d (which expects parameters of type "double") when you put there "float" ("1.0f -> 1.0").

Share this post


Link to post
Share on other sites
thanks a lot about the help.
here the full code of the draw.if(ySpeed != 0 || xSpeed != 0)
deg = fmod(atan2(yP-(yP+ySpeed),xP-(xP+xSpeed))/3.14159265f*180.f,360.f);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.5f, 0.5f, 0.f);
glRotatef(deg, 0.f, 0.f, 1.f);
glTranslatef(-0.5f,-0.5f, 0.f);
glMatrixMode(GL_MODELVIEW);



glEnable (GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBegin(GL_QUADS); //draw...
glTexCoord2d(1.0,1.0);glVertex3f( xP, yP2, 0);
glTexCoord2d(0.0,1.0);glVertex3f( xP2, yP2, 0);
glTexCoord2d(0.0,0.0);glVertex3f( xP2, yP, 0);
glTexCoord2d(1.0,0.0);glVertex3f( xP, yP, 0);
glEnd();


glMatrixMode(GL_TEXTURE);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glDisable (GL_BLEND); }


init func of opengl:
glClearDepth(1.f);
glClearColor(0.f, 1.f, 1.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
GlTextLoad("pic.png", 0); //load picture...
GlTextLoad("Menu1.png", 1);
GlTextLoad("Menu2.png", 2);
GlTextLoad("Menu3.png", 3);
GlTextLoad("pic1.png", 4);
GlTextLoad("pic2.png", 5);
GlTextLoad("Back.png", 6);
glEnable(GL_TEXTURE_2D);



gltexload func: (load texture with sfml)
bool WinS::GlTextLoad(char* fName, int fNum)
{


if(!texture[fNum].LoadFromFile(fName))
{
MessageBox(NULL, "Can't load the texture...", "Eror", MB_OK);
Running = false;

return false;
}

texture[fNum].CreateMaskFromColor(sf::Color(1, 1, 1 , 0));
return true;
}


resize opengl
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, float(width) / float(height), 1.0f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();



This is in the start of the render func:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);




I don't think there is more relevant code...

Share this post


Link to post
Share on other sites


texture[fNum].CreateMaskFromColor(sf::Color(1, 1, 1 , 0));


I think this operation overwrites image's mask channel. Why to do this if your image already has a mask? (P.S. Just currently looked at SFML documentation)


Share this post


Link to post
Share on other sites
I added it just now, for check if it will do something, and forgot to delete it.
Without that it still happen.


I found what the problem.
SFML load the texture as 8 bit...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!