Lets see if I understand this.

Started by
5 comments, last by Goober King 20 years, 1 month ago
Ok. I was going to write a program using Direct Draw but I switched to using GCC3.2(I think) with the Dev-Cpp IDE. I already have all the stuff for using DD but I can''t get the programs to stop crashing for some unkown reason. Soooo I was looking into maby using OpenGL for the program which seams to work fine and dandy. Then I could also do it under linux. My understanding is its faster to fake 2D with 3D anyway. However, while it looks doable(though odd) I have at least one concern at the moment. Ok maybe two. I''m sure more will come later. I''m not too clear on how one simulates see through areas. Like if I wanted to use make say a mouse pointer. I''ve seen some reference to saving an Alpha channel with the texture image to define the drawing area. Thats easy if it works but there is a NeHe tutorial that makes it sound like you have to do some funky dancing using a black and white mask then redraw into the white(?) areas. Which sounds like a pain in the ass. All of it sounds like more trouble than "Hey Direct Draw. Don''t go blitting anything thats black. OK." Then I''ve seen something saying you cant use images smaller than 64x64 which is tooo big for what I need. I''ve also seen something say your ok as long as its just a power of 2. 16x or 32x may be what I need. I''ve only been looking into OpenGL for a couple of hours so I don''t understand everything yet. But if I am going to invest oodles of time in this I want to make sure I can actually get it to do what I need it to do.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
Advertisement
You can get it to do what you want (at least everything you''ve mentioned in your post).

quote:
Then I''ve seen something saying you cant use images smaller than 64x64 which is tooo big for what I need. I''ve also seen something say your ok as long as its just a power of 2. 16x or 32x may be what I need.


The second something is correct.

quote:
I''m not too clear on how one simulates see through areas. Like if I wanted to use make say a mouse pointer. I''ve seen some reference to saving an Alpha channel with the texture image to define the drawing area. Thats easy if it works but there is a NeHe tutorial that makes it sound like you have to do some funky dancing using a black and white mask then redraw into the white(?) areas. Which sounds like a pain in the ass. All of it sounds like more trouble than "Hey Direct Draw. Don''t go blitting anything thats black. OK."


Using the alpha channel you can create more complex ''see through'' effects (more appropriately called blending) then simple colour keying. You can either have the alpha channel set during the artistic production process (i.e. in the drawing package), or you can use a simple loop through the pixels in your image to create a sort of colour keyed texture.

char image[w*h*3];char texture[w*h*4];for(int j = 0; j < h; j++)  for(int i = 0; i < w; i++)  {    char alpha = 0x00;    if( image[((i + (j*w)) * 3) + 0] == colour_key_red &&        image[((i + (j*w)) * 3) + 1] == colour_key_gren &&        image[((i + (j*w)) * 3) + 2] == colour_key_blue)       alpha = 0xff;    texture[((i + (j*w)) * 4) + 0] = image[((i + (j*w)) * 3) + 0];    texture[((i + (j*w)) * 4) + 1] = image[((i + (j*w)) * 3) + 1];    texture[((i + (j*w)) * 4) + 2] = image[((i + (j*w)) * 3) + 1];    texture[((i + (j*w)) * 4) + 3] = alpha;  } 


Then you''d draw a quad with blending enabled (after a bit of extra setup like textures, viewport etc):

glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA);

glBind(GL_TEXTURE_2D,texture_id);

glBegin(GL_QUADS);
...
glEnd();

(exact blending function needed may not be as shown!)

So it is well worth the time invested.
If it can all be done with a saved alpha channel then what is the point of doing things like this...

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20

It takes twice as long as since you have to draw the shape once in black then again to fill the space. There is a very noticable speed difference on just the demo the lesson 20 creates when you toggle the use of blending vs masking. Since almost every image will need to have something cut out of it something that doubles the render time seams like bad news.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
There are many ways to achieve these kind of effects using OpenGL (or D3D), the blending system is extremely powerful (and even more so with fragment programs).

The alpha channel method I described above is sufficient for ''emulating'' colour-keyed sprites under OpenGL. YMMV of course, depending on exactly what you are trying to achieve. Put in a few weeks research and it all will become clear .
Just use a nicer paint program (Photoshop, Gimp, etc) with a transparent background. Draw your image, leaving the rest blank. Save as a TGA or other format with alpha. If blending is enabled, you should have just the drawn part displayed.
quote:Original post by nagromo
Just use a nicer paint program (Photoshop, Gimp, etc) with a transparent background. Draw your image, leaving the rest blank. Save as a TGA or other format with alpha. If blending is enabled, you should have just the drawn part displayed.


Thats what I want to hear. I guess its time to throw down some code and see what I can do.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
Thanks for clearing things up. I''ve got TGA textures loaded and working nicly.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork

This topic is closed to new replies.

Advertisement