Jump to content
  • Advertisement
Sign in to follow this  
Kjell Andersson

OpenGL OpenGL legacy to shader mapping

This topic is 425 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 trying to get some legacy OpenGL code to run with a shader pipeline,

The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.

I've got a version 330 vertex shader to somewhat work:

#version 330

uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;

layout(location = 0) in vec4 Vertex;
layout(location = 2) in vec4 Normal; // Velocity
layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location?

out VertexData {
    vec4 color;
	vec3 velocity;
	float size;
} VertexOut;

void main(void)
{
	vec4 p0 = Vertex;
	vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f);
	vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz;

	VertexOut.velocity = velocity;
	VertexOut.size = TexCoord.y;
	gl_Position = osg_ModelViewMatrix * Vertex;
}

What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.

What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.

Question:

What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?

 

Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.

Share this post


Link to post
Share on other sites
Advertisement

The only well-defined standard location is 0 for the vertex position attribute. The use of location 2 for normals and similarly for other attributes is a NVIDIA-specific thing, and will most probably break you hard on other vendors.

Please see this discussion on SO: https://stackoverflow.com/a/528824/87969

If you only care about those devices and are happy to rely on vendor-specific behaviour, the mapping should then be that gl_MultiTexCoord0 is at location 8, according to the docs.

Share this post


Link to post
Share on other sites

Thank you Zao, you saved my day! You gave the exact answer I was looking for.

I had my doubts about interoperability between legacy and modern OpenGL, and you confirmed it. It is however as you say, the texture coordinate was to be found at position 8 when I tested it, but since this may be NVIDIA specific I have to find a way around it.

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!