I am having a problem with my code. I have a working program that draws text and graphics to three screens. I am trying to create a textured quad to underlay the current graphics, but the quad will not show up.
I added this initialization code before the main loop (called once for each output display):
/* Generate the vertex and fragment shader programs for background rendering */
if((Image_Program[Output] = create_program("text/capture.v.glsl", "text/capture.f.glsl")) == 0)
return 0;
/* Create the VBO and VAO and EBO for the background texture quad */
glGenVertexArrays( 1, &VAO[Output] );
glGenBuffers( 1, &VBO[Output] );
glGenBuffers( 1, &EBO[Output] );
glBindVertexArray( VAO[Output] );
glBindBuffer( GL_ARRAY_BUFFER, VBO[Output] );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, VBO[Output] );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0 );
glEnableVertexAttribArray( 0 );
glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)) );
glEnableVertexAttribArray( 1 );
glBindVertexArray( 0 );
unsigned char blank[1920 * 1080 * 3];
int Input;
/* fill the image with a grey image */
memset( blank, 255, 1920 * 1080 * 3 );
/* Generate the textures */
glGenTextures( VID_Count, Capture_Texture[Output] );
/* Loop across all the inputs */
for( Input = 0; Input < VID_Count; Input++ )
{
/* Bind the texture */
glBindTexture( GL_TEXTURE_2D, Capture_Texture[Output][Input] );
/* set the texture parameters */
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
/* Set the texture filtering */
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
/* create and initialize texture */
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, Input_Config[Input][0].Width, Input_Config[Input][0].Height, 0, GL_RGB, GL_UNSIGNED_BYTE, blank );
/* Un-bind the texture */
glBindTexture( GL_TEXTURE_2D, 0 );
}
the function create_program is already working for the shader programs used by the text functionality, so I believe it works. It does not return any errors.
the data used by the init is:
GLfloat vertices[20] = { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top Right
1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // Bottom Right
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // Bottom Left
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f }; // Top Left
GLuint indices[6] = { 0, 1, 3, // First Triangle
1, 2, 3 };// Second Traingle
and finally, the code executed in the main loop is:
glActiveTexture(GL_TEXTURE1);
glBindTexture( GL_TEXTURE_2D, Capture_Texture[Output][VID_EOW] );
glUseProgram(Image_Program[Output]);
glBindVertexArray(VAO[Output]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
glUseProgram(0);
I am using GL_TEXTURE1 for this texture because the text code already uses GL_TEXTURE0
I took most of this code from the http://www.learnopengl.com website. Ultimately, I will have another thread updating the texture with a real-time image capture. But for now I am just trying to get a white background.
oh yeah, here is the vertex shader program:
#version 450
layout (location = 0) in vec3 coord;
layout (location = 1) in vec2 texcoord;
out vec2 texpos;
void main(void) {
gl_Position = vec4(coord, 1);
texpos = texcoord;
}
and the fragment shader:
#version 450
layout (location = 0) in vec2 texpos;
layout (location = 1) uniform sampler2D tex;
void main(void) {
gl_FragColor = texture(tex, texpos);
}
I thought I had problems with my matrix math again, so I just put the quad at z=0.0 to avoid the whole clip-space issue. I would appreciate any help.