Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Alpha channel not working :(

This topic is 4668 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

hi, I am making a simple tile game, drawing solid-color (no texture, no lights) quads. Lately I tried to add the use of alpha channel for translucency but failed miserbly. Each quad rendered fully opque. Can someone help me? I am using SDL and OpenGL the screen is setup with
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	//SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);

	m_iVideoFlags = 0;
	m_iVideoFlags |= SDL_OPENGL;
	m_iVideoFlags |= SDL_GL_DOUBLEBUFFER;
    m_iVideoFlags |= SDL_HWPALETTE; 
    m_iVideoFlags |= SDL_RESIZABLE; 
    if ( videoInfo->hw_available )
		m_iVideoFlags |= SDL_HWSURFACE;
		m_iVideoFlags |= SDL_SWSURFACE;
    if ( videoInfo->blit_hw ) 
		m_iVideoFlags |= SDL_HWACCEL;
	//m_iVideoFlags |= SDL_FULLSCREEN;
	// Attempt to create a WIDTHxHEIGHT window with 32bit pixels.
	if (SetSize(m_iWidth, m_iHeight) ==false)

SetSize changes video mode and calls the openGl 2d code from the forum faq. the quad painting is:
//R,G,B,A are in byte values (0..255)

I tried puting the blend function before each tile, or before the enabling, I tried different blend functions, and still nothing: each quad is always opaque. thanks in advance, Iftah.

Share this post

Link to post
Share on other sites
I don't know SDL so this is just a guess, but if SetSize does the display creation then your earlier glEnable(GL_BLEND) calls won't be having any effect as theres no context for them to apply to. Try moving them to just before you draw your quad.

Share this post

Link to post
Share on other sites
ooops... [blush]

you are right, SetSize destroys the openGL context and creates a new one,
all the enabling and function setting should be there.

I moved it to that place and everything works now :)

ps. SetSize is my function, not SDL's

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!