VBO and trasnparency

Hi ogl’ers,

I’m wanting to keep transparency data in different containers from that of the colour data. I know I can keep the data in another buffer object, but can the draw itself use another buffer? So instead of calling glColorPointer(4,…), I call it with glColorPointer(3,…), and then use another buffer to add in the transparency data. Can this be achieved with some gl___() routine? Or will this require something else?

I’m not entirely sure what to look for with regards to this, most searches I came across were talking about textures. But I’m wanting to do this with plain data, not a texture bitmap. Is someone able to point me in the right direction of where and what I need to be looking at to achieve this? Cheers,

WP.

You can write your own shaders and use uniforms for the alpha value.

Ok, I am getting something drawn with the colours and alpha I’m asking for, but I’m not getting the projection matrix etc right. This is what I’ve got in the draw function:


void My_Window::DrawGL(void)
{
	...

	glfloat viewMatrix[16];
	glGetFloatv(GL_MODELVIEW_MATRIX,viewMatrix[0]);
	glUniformMatrix4fv(4,1,GL_FALSE,&viewMatrix[0]);  // is the location set correctly here?
	
	GLfloat projectionMatrix[16];
	glGetFloatv(GL_PROJECTION_MATRIX,projectionMatrix);
	glUniformMatrix4fv(8,1,GL_FALSE,&projectionMatrix[0]);  // and again here?

	...
}

And this is most of the shader:


"uniform mat4  worldMatrix;""
"    // not sure what, or how many, I should be using here
"uniform mat4  viewMatrix;""
"
"uniform mat4  projectionMatrix;""
"
...
	
void main()
{
	"gl_Position = worldMatrix * vec4(position,1.0);""
"
	"gl_Position = projectionMatrix * gl_Position;""
"
	...
}

I feel I’ve got the passing of colour and alpha data right, but I think I’m not understanding how to get and apply the matrices. I get some strange results depending on how I have it setup, so I can see it “working” - but not working. What do I need to be fiddling with here?

WP.

is the location set correctly here?

Well, since you hard-coded a uniform location, yet aren’t setting that uniform location from within your shader… no.

Uniform locations, when not [assigned explicitly by you](Uniform (GLSL) - OpenGL Wiki (GLSL)#Explicit uniform location), are arbitrary numbers assigned by the shader compiler. So if you didn’t assign them, you must query them, for each program, from the API.

Also, it’s not clear why you’re defining 3 matrices, but only using two.

Hi Alfonse,

the 3 matrices came about from various searches which all seemed to do things differently - some used 2, some used 3, some used completely different terminology altogether (possibly using external library api-specific?). I think ending up only using 2 above was just another one of the ‘experiments’ I had been trying out.

A couple of things - I’ve updated the shader to include “in layout(location…)” for the uniforms. I had these for other shader objects, but not the matrices. Again - various things I read did things differently. With ‘location’ in mind, I read that each mat4 should be assigned with 4 ‘spare indexes up the sleeve’ (for lack of a better term), so the first location at 0, the next at 4, the next at 8 etc. Is this correct (using set uniform locations)?

How many matrices do I need to pass for this to work? The user has an option of switching between glOrtho() and gluPerspective(), do both of these require different matrices sent?

WP.

This is the fundamental crux of your problem. You’re trying to build code by slapping pieces of it together from various places you’ve seen, then fiddling around with it until you get something that appears to work.

This process did not work very well for Dr. Frankenstein. So I can’t advise it.

What you need to do is step back and figure out what those “things” you found were actually doing. Take some time to understand what “worldMatrix”, “viewMatrix,” and “projectionMatrix” actually mean. If the meaning of these variables is not explained in whatever you’re looking at, then go find something else.

“in” and “uniform” are both storage qualifiers. A variable cannot be both a shader stage input and a uniform at the same time. That’s like saying a variable can be both const and mutable.

I have no idea where you read that from. I’m guessing you were reading about vertex attributes, not uniforms and got confused between the two.

Why would you not simply send the appropriate matrix to the shader? A matrix is a matrix is a matrix, and the only difference mathematically between an orthographic projection and a perspective one is the numbers you put into the matrix.

Also, if you’re using OpenGL’s matrix stuff, you really ought to just use GLSL’s compatibility features for having shaders directly access OpenGL’s matrices. There’s really no point in using OpenGL to compute a matrix, then doing a glGet and passing it as a uniform, when shaders can just access the matrix you computed.

And if you don’t want to use GLSL’s compatibility features, just use a matrix library rather than OpenGL’s functions.