Jump to content

  • Log In with Google      Sign In   
  • Create Account


texture, background delete


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 mentaman   Members   -  Reputation: 99

Like
0Likes
Like

Posted 21 December 2011 - 01:46 AM

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 transparent.


Posted Image

You see the green background they have?




Sponsor:

#2 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 21 December 2011 - 01:59 AM

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 transparent.


Posted Image

You see the green background they have?

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

#3 mentaman   Members   -  Reputation: 99

Like
0Likes
Like

Posted 21 December 2011 - 02:09 AM

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

texture[fNum].LoadFromFile(fName)


#4 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 21 December 2011 - 02:38 AM

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).

#5 mentaman   Members   -  Reputation: 99

Like
0Likes
Like

Posted 21 December 2011 - 02:44 AM

Posted Image

this is the picture

#6 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 21 December 2011 - 02:57 AM

Posted Image

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").

#7 mentaman   Members   -  Reputation: 99

Like
0Likes
Like

Posted 21 December 2011 - 03:18 AM

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...

#8 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 21 December 2011 - 04:02 AM

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)




#9 mentaman   Members   -  Reputation: 99

Like
0Likes
Like

Posted 21 December 2011 - 04:05 AM

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...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS