Jump to content
  • Advertisement
Sign in to follow this  
citronrock

OpenGL i need some help !! thx (layer, color key...)

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

i'm a proper beginner in openGl , i worked for a long time with directX, but now, i really wanna change, it's boring me a lot.... but i can't find a tutorial whith an explanation about pictures, layers, alpha colors.... i just want to see on my screen : a picture ( in full screnn ) , and a second picture on the first ( so i need to declare a key color on this , and the 2nd picture like a layer...) , then i'd like to know how i can "destroy" the second one like a worms-like, what i need to know ? thx a lot for this , thx indeed.

Share this post


Link to post
Share on other sites
Advertisement
To create a texture for rendering, you'll need to use glTexImage2D(). Don't forget to create it with glGenTextures() first. Also, don't forget to set the texture filters using glTexParameteri(), or you'll be scratching your head while wondering why it's not working.

To render a texture like this, the best way is to bind it to a quad using glBindTexture(), then render it as necessary. Don't forget to enable texturing using glEnable().

To render a quad that takes up the full screen, you can use this code:

//This gets the current matrix mode, so we can restore it later
GLint matrixMode;
glGetIntegerv(GL_MATRIX_MODE,&matrixMode);

//Assuming you're using your own projection matrix, this wont hurt it
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(-1.0f,1.0f,-1.0f,1.0f,-1.0f,1.0f);

//This wont hurt your translations/rotations either
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glBegin(GL_QUADS);
glVertex3f(-1.0f,-1.0f,0.0f);
glVertex3f(+1.0f,-1.0f,0.0f);
glVertex3f(+1.0f,+1.0f,0.0f);
glVertex3f(-1.0f,+1.0f,0.0f);
glEnd();

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

//Restore the old matrix mode
glMatrixMode(matrixMode);



Most (if not all) of that code is not necessary, if you learn a little more about Open GL.

To enable transparency in images, you'll need to enable alpha testing (so you can control the transparency (helps with the linear filter)), and blending. Then you'll need to use a blending function like this: glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA).

To change the colour of a quad, you can use glColor** (there's numerous functions, all of them work). To change the colour of a textured quad, you'll need to change the texture's environment mode using glTexEnvi().

To destroy parts of an image (like in Worms), you'll need to keep the image data, and use glCopyTexImage2D() to update it as necessary.

Finally, don't forget to delete your textures using glDeleteTextures().

Share this post


Link to post
Share on other sites
opengl like d3d doesnt support colorkeys, u can achieve the same thing (and more) with having an alpha channel in the texture.
set alpha test to greater > 0.0 with your woems like world texture set all the alpha to 1, now to remove a part of that texture so it doesnt get drawn change part of that textures alpha channel to 0 with glTexSubImage2d(...)

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!