Help? Yeah Righ!

Is this a help forum or a fudge forum!
If it is a help forumn->

could some one please show me how to draw a subimage with transparent areas on top of another image!

Every time I try using this ****ing code.
The transparent areas turn black instead of showing the image beneath.

glClearColor(0.0f, 0.0f, 0.0f, 1.0f) ;
glShadeModel(GL_FLAT);
file://glEnable(GL_DEPTH_TEST);

int x,y;
for(x =0; x < 128; x++)
{
for(y = 0; y < 128; y++)
{
Tile[x][y][0] = 255;
Tile[x][y][1] = 0;
Tile[x][y][2] = 0;
Tile[x][y][3] = 255;

}
}

pngLoadRaw(“E:\Grass.png”,&info[0]);
pngLoadRaw(“E:\Marsh.png”,&info[1]);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128,
0, GL_RGBA, GL_UNSIGNED_BYTE,Tile) ;

glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGB,GL_UNSIGNED_BYTE,info[0].Data);
glTexSubImage2D(GL_TEXTURE_2D,0,0,64,64,64,GL_RGB,GL_UNSIGNED_BYTE,info[0].Data);
glTexSubImage2D(GL_TEXTURE_2D,0,64,0,64,64,GL_RGB,GL_UNSIGNED_BYTE,info[0].Data);
glTexSubImage2D(GL_TEXTURE_2D,0,64,64,64,64,GL_RGB,GL_UNSIGNED_BYTE,info[0].Data);

void COpenGLView: rawGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE,info[1].Data);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2i(10,138);
glTexCoord2f(0,1); glVertex2i(10,10);
glTexCoord2f(1,1); glVertex2i(138,10);
glTexCoord2f(1,0); glVertex2i(138,138);
glEnd();

glDisable(GL_BLEND);
glDisable(GL_ALPHA_TESTglFlush();

glDisable(GL_TEXTURE_2D);
}

Opengl easier then D3D!
My arsehole!

As far as I know, glTexSubImage2d REPLACE the values of the texture. It is not like multitexturing.

My guess is what your are trying to is some sort of decal. If you want to do that you should look into multitexuring.

Or you could apply a polygon over an another using the stencil buffer to make sure you get no z fighting

Why the f#ck are you so offending?

First of all this is an open forum, so peapole like you could answer questions.
If you are lucky you may get an answer, but there is no rule that you have to get one.

If you had read the spec for the function you are using you would know that it REPLACES the pixel as Gorg just posted to you. If you want to alpha blend your new subimage on the orignal texture, you have to do the alpha blend on your f#cking own.

If you had any idea of graphics in general you would know that.

And this dosen’t have anything to do with opengl, you have to do the same in d3d.

You may read the f#cking manual before you ask silly questions and post them into both (beginner/advanced) sections.

I think this was the last time YOU got ANY answers in this forum.

FYI: the alpha value 0 means completly
transparent.

Get a glue.

I love the arugments of D3D being “easier” than OpenGL

to that I say “Great!”

I bet tracing a picture of Donald Duck is alot “easier” than drawing one yourself…

“easier” does not mean “better”

as soon as people realize this, i think alot of conflict will be dimenished

Originally posted by ironduke:
[b]I have tried it with modulate/decal etc…
with different alpha blending constants but it is always black!

Hey YouPissedMeOff!
Blow Me!
Jagoff![/b]

cool. we can resort to insults and bullying to get our way. very mature, ironduke. I shudder to think that one day you might right safety critical software involving trains and people’s lives. (I’ve been there, done that, albeit in a simulation with a toy train in our undergrad course, and it’s scary to think what “graduates” are churned out).

read my reply in the same post to the advanced discussion forum.

oh, and try to grow up. it’ll make it so much easier for everybody else

Thanx for the tip john, but you didnt answer my question!

Do it NOW!

ironduke, it won’t work like that. glTexSubImage2D REPLACE the value of the texture. there is no blending. The replacing is done in memory, not in the framebuffer.

Use multitexturing, or have a second polygon over the first one you make and texture map it with your texture and blend it.

Can’t help it. Must reply.

Ya know what… do it in D3D, or figure it out yerself.

An attitude like that, you MUST work for Microsoft.

To Gorg(not the other unhelpful jagoffs)

So what you are saying is gltexsubImage currently doesnt support blending with the texture it is going to be placed on, only blending with the current selected color!

If so Extension please NVidia,SGI!

Sorry ironduke, you wont get any extension for this, 'cause it’s a rather useless to alphablend a texture like this. You should use multitexturing.

That’s right ironduke, there is no blending done.

And I also don’t think there will ever be an extension for that, because there is already one! Multitexturing!

Even though Multitexturing seems advanced for what you want to do, it is conceptually the same thing than blending new colors with a texture without using more geometry.

I have heard alot about Multitexturing, but I did not want to use it as I hear many vendors drivers still dont support it!

that’s not true. I am not aware of any comme vendor (ATI, NVIDIA, 3DFX, MATROX) that doesn’t support multitexturing today.

I may give it a go Gorg if This Idea fails->
The reason I wish to use sub images is to reduce the number of quads by a factor of 4.

Is more images less triangles more efficient?

I am going to manually blend the two images by accessing each byte in a loop and changing that byte if its alpha is a certain value.

does this sound right.

It’s going to be slower than multitexuring :

reason : the graphic boards has special instruction to blend a bunch of values together. With your loop, you’ll be using the CPU and it’s going to be some mov, add, mult intructions(if you know anything about assembly) It’s going to be real slow if your texture is big.

The only way you could maybe get the same performance than multitexuring if you do the blending manually is through SSE instructions wich are only on PIII.

My best advice for you is: if you don’t want any hassle, just do your loop, but If you want speed, you better go with multitexuring wich is a good technique to learn. You can do a lot of cool stuff with it.

Trust me, multitexuring is worth checking out!

good luck

The thing is gorg i wish to tile each quad 2 by 2 images, when you texture a quad, it either repeats the texture or clamps creating a smear inthe rest of the quad?

The only way around this in multitexturing, is to make a transparent texture in photoshop which is twice the size of each tile, copy my tile to the topleft, then do the same with a new image for the topright and so on?

I hope you get that!

Oh, I see what you want to do. hmm. This should work with glTexSubImage, but I don’t see where you want blending tough. Here is what I would do:

1.Create a black 128X128 black Texture.
call glBindTexture on it.

  1. Then let’s say you have an array(color[4]) of 4 subtexture of with and height = 64 you want to use you call glTexSubImage4 times on that black texture:

glTexSubImage1 : xoffset = 0, yoffset = 128 width = heigth = 64

glTexSubImage2 : xoffset = 64, yoffset = 128,

glTexSubImage3 : xoffset = 0, yoffset = 64

glTexSubImage4 : xoffset = 64, yoffset=64

glTexSubImage replace values from left to right and top to bottom.

Now to use your modified black texture in the code, just call glBindTexture on that texture.

That should do the trick. And yep, for what your are trying to do, doing multitexuring is maybe pushing things a little too much.

I think this is what you tried to do in your code, but there are some weird things in it, like 5 glTexsubImage calls. Try it again with the template I gave you and tell me if it works. If it doesn’t I’ll try it myself in real code just to see if I haven’t overlooked something.

You could still try Multitexturing though, you might still get better performance depending on your card because glTexSubImage2d is not really optimised on all cards. But try with subimage first

The reason I need blending is to place another tile over one of the previous tiles.

I am writig a map editor for Sid Mier’s Antietam.

Imagine the corner of each quad is the center of a map square?

its terrain would be in the quads above left/right, below left/right.

The transparency is needed to save me creating dozens of images ie grass with marsh overlayed, wheat with river overlayd and so on.

Do you see?

Thanx for ye help.

Waouhaouahaoauh !

Ironduke, take your pills : you’ve been almost kind with Gorg and you said “Thank you”…

Are you drunk or what ?!?!?

Eric