winterhell's picture

GL.Begin disables shader and renders with the fixed pipeline?

So, I have a shader set up to render my geometry using VBOs, and then I want to have some dynamic quads in the scene with Z-buffer and everything.

My code is

 
                     GL.BindTexture(TextureTarget.Texture2D, pModel.diffuseTexture.id);
                     GL.BindBuffer(BufferTarget.ArrayBuffer, pModel.positionVboHandle);
                     GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0);
                     GL.BindBuffer(BufferTarget.ArrayBuffer, pModel.texcoordVboHandle);
                     GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);
 
                     GL.DrawArrays(PrimitiveType.Triangles, 0, pModel.verticesOGL.Length);
 
                     GL.BindTexture(TextureTarget.Texture2D, sprite.id);
                     GL.Begin(PrimitiveType.Quads);//same result for triangles
 
                     GL.TexCoord2(0, 1); GL.Vertex3(scale * cosPAngle + posX, scale * sinPAngle + posY, posZ);
                     GL.TexCoord2(1, 1); GL.Vertex3(scale * -cosMAngle + posX, scale * -sinMAngle + posY, posZ);
                     GL.TexCoord2(1, 0); GL.Vertex3(scale * -cosPAngle + posX, scale * -sinPAngle + posY, posZ);
                     GL.TexCoord2(0, 0); GL.Vertex3(scale * cosMAngle + posX, scale * sinMAngle + posY, posZ);
                     GL.End();

The quad ends up rendering by the fixed function pipeline, while the VBOs render with the shader. Is this normal behaviour and do I have alternatives?
Point sprites wont work for me as some quads need to be much bigger than 64x64 pixels and they get clipped if the center is off-camera.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Are you using the same shader in both cases? If so, your TexCoord2 & Vertex3 calls are swapped compared to your VertexAttribPointer calls:

                     GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0); // pModel.positionVboHandle
                     GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0); // pModel.texcoordVboHandle
                     // compared to:
                     GL.TexCoord2(0, 1);
                     GL.Vertex3(scale * cosPAngle + posX, scale * sinPAngle + posY, posZ);

Vertex submission (VBOs, vertex arrays, display lists, immediate mode) does not affect shader usage, you can use shaders in all cases.

winterhell's picture

I'm rendering the scene just like in the above code. If I draw another VBOs after the GL.End they render with the shader as well.
Changing the order of GL.TexCoord2 and GL.Vertex3 does not fix the problem(although it alters the texture coordinates)
Could this be related to the OGL 3.1 Core/Compatibility stuff? I havent set anything explicitly, but still who knows.

winterhell's picture

I ended up making VBOs for the vertices and the texture coordinates of the quad with BufferUsageHint.StreamDraw, and now I'm updating them before each render. At least the GL calls are less.