ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1) SDL_SetColorKey doesn't work with OpenGL (SDL_GL_SwapBuffers).
How to set the transparent color?
2) When I load PNG with "transparent area" (tried to use PNG instead of the above problem with BMP), an image becomes distorted.
How to fix it?
With OpenGL you usually do transparency by doing alpha blending or alpha test. With blending you can get a nice semi-transparency effect.
If you do a Google search on alpha blending you'll find lots of info, but just as a quick and dirty guide to get it working:
First, you'll need an image format that supports an alpha channel. TGA files are great for this. The Gimp works well for drawing in that alpha channel as well. Google that for some tutorials on how to work with alpha channels in The Gimp.
Enable blending with glEnable(GL_BLEND);
Set the blending function with glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA_MINUS_ONE);
Draw your blended stuff last
Either draw your blended stuff in proper back to forward order, or disable depth writing before drawing the blended stuff with glDepthMask(false); (Make sure to enable it again with glDepthMask(true) when you draw your solid items again
For a simple alpha test instead (where either a pixel is drawn or not, no blending is done)
Same as first point above. Again, TGAs are a great format for alpha channel support
Enable alpha test with glEnable(GL_ALPHA_TEST);
You might have to play with the alpha function a bit. I use blending more than alpha test, but I think what you want here is: glAlphaFunc(GL_GEQUAL, 0);
I understood: in glTexImage2D and gluBuild2DMipmaps I used GL_RGB, not GL_RGBA.
I just can't get one thing: I've made glClearColor (0.0f, 0.0f, 0.0f, 1.0f)
But the screen is cleared as glClearColor (0.3f, 0.3f, 0.3f, 1.0f)!
And when I've made glClearColor (1.0f, 1.0f, 1.0f, 1.0f), the screen was cleared as glClearColor (0.7f, 0.7f, 0.7f, 1.0f)!
And it happens because of the loaded PNG! When no PNG loaded glClearColor (0.0f, 0.0f, 0.0f, 1.0f) works! What's it? Is it a case of an image border?
What is wrong here? I don't get any error, so all should work correctly, but it doesn't.
GL_REPEAT doesn't work: a texture is spread all over a polygon, and not textured repeatedly.
I've commented glTexImage2D, since you've noticed in another (long ago) post that it shouldn't be used with gluBuild2DMipmaps... but nothing has changed. The texture is still spread all over a polygon...
I've looked at NeHe's and... found no gluBuild2DMipmaps with GL_TEXTURE_WRAP_S
Although I've noticed such trick in the 20th lesson:
Code:
glTexCoord2f( 0.0f, 4.0f ); glVertex3f( -1.1f, -1.1f, 0.0f );
and so on
Whell this trick makes the texture repeat 4 times across the polygon. But it doesn't care of a texture's size.
Right, if your texcoords only ever go from 0-1, you will never get wrapping. (Because 0 is one edge, and 1 is the other edge, everything in between is a fraction of that.)
If you want repeating based on the size of the image, you're going to have to do a little more work. An easy way if you are just displaying a textured quad, is just to set the projection to an ortho projection the size of the window, and set the texcoords to be something like window coordinate/image size.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.