Regarding Shader Attributes

I get the basic gist of how shaders work, but looking at Matt DesLauriers’ excellent tutorials, he’s using the SpriteBatch object for quite a bit… this left me wondering how you would “manually” pass in the Position, Color, and TexCoord attributes to the Vertex shader.

These are usually handled by the SpriteBatch object, but I’m using some old-school style rendering for the FBO as follows…

int attributeLoc = ARBShaderObjects.glGetUniformLocationARB(currentShader, "texture");
ARBShaderObjects.glUseProgramObjectARB(currentShader);								
ARBShaderObjects.glUniform1iARB(attributeLoc, fboTexture);

GL11.glColor4f(1, 1, 1, 1);
GL11.glBegin(GL11.GL_QUADS);
				
// Top Left
GL11.glTexCoord2f(0.0f, 1.0f); 
GL11.glVertex2i(x, y);  		
// Top Right
GL11.glTexCoord2f(1.0f, 1.0f); 
GL11.glVertex2i(x + width,  y); 		
// Bottom Right
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex2i(x + width, y + height);		
// Bottom Left		
GL11.glTexCoord2f(0.0f, 0.0f); 		
GL11.glVertex2i(x, y + height);	
GL11.glEnd();

What variables can I attach to the shader attributes in place of what SpriteBatch would usually provide?

  • Steve

I don’t think you can use immediate mode and shader attributes together.

The function you’re looking for is glVertexAttribPointer(), but it’s for use with VBOs or VAOs.

As far as I’m aware whenever you call a function like glVertex3f() it passes the values to openGL, your shaders pick up the info in gl_Vertex/gl_TexCoord/gl_Color, etc.

Edit: I misunderstood the question.

maybe i missunderstand too … but

i think you can use https://www.opengl.org/sdk/docs/man/html/glVertexAttrib.xhtml to assign all kind of values to generic vertex attributes … while drawing immediately, like in your code-snipplet.