I recently started learning tessellation and today I was trying to draw a triangle after tessellation so that I can see all the tessellated smaller triangles using gl_PolygonMode(GL_FRONT_AND_BACK, GL_LINE). But for some reason the output is just a coloured background without any triangle in it.
For the tessellation, I make a control shader and an evaluation shader and then attach them to my program.
Is it defaulting to GL_FILL mode for some reason?
I am not able to figure out what’s wrong since I am just following along my book (OpenGL Superbible 7th Edition).
How can I fix this?
[QUOTE=MinorMapillai;1292073]I recently started learning tessellation and today I was trying to draw a triangle after tessellation so that I can see all the tessellated smaller triangles using gl_PolygonMode(GL_FRONT_AND_BACK, GL_LINE). But for some reason the output is just a coloured background without any triangle in it.
For the tessellation, I make a control shader and an evaluation shader and then attach them to my program.
Is it defaulting to GL_FILL mode for some reason?
I am not able to figure out what’s wrong since I am just following along my book (OpenGL Superbible 7th Edition).
How can I fix this?[/QUOTE]
It is hard to guess what might be wrong without any code snippets.
The code for the entire program is:
GLuint compile_shaders(void)
{
GLuint vertex_shader;
GLuint fragment_shader;
GLuint control_shader;
GLuint evaluation_shader;
GLuint program;
// Source code for Vertex Shader
static const GLchar * vertex_shader_source[] =
{
"#version 450 core
"
"
"
"// offset and color are input vertex attribute
"
"layout (location = 0) in vec4 offset;
"
"layout (location = 1) in vec4 color;
"
"
"
"//Declare VS_OUT as an output interface block
"
"out VS_OUT
"
"{
"
" vec4 color; //Send color to next stage
"
"}vs_out;
"
"
"
"void main(void)
"
"{
"
" //Decalre a hardcoded array of positions
"
" const vec4 vertices[3] = vec4[3](vec4(0.25, -0.25, 0.5, 1.0),
"
" vec4(-0.25, -0.25, 0.5, 1.0),
"
" vec4(0.25, 0.25, 0.5, 1.0));
"
"
"
" //Index into our array using gl_VertexID
"
" gl_Position = vertices[gl_VertexID] + offset;
"
"
"
"//color = vec4(1.0, 0.0, 0.0, 1.0);
"
"//Output fixed value for vs_color
"
"vs_out.color = color;
"
"}
"
};
// Source code for Fragment Shader
static const GLchar * fragment_shader_source[] =
{
"#version 450 core
"
"
"
"//Declare VS_OUT as an input interface block
"
"in VS_OUT
"
"{
"
" vec4 color; //Send color to next stage
"
"}fs_in;
"
"
"
"//Ouput to the framebuffer
"
"out vec4 color;
"
"
"
"void main(void)
"
"{
"
"// Simply assign the color we were given by the vertex shader to our output
"
" color = fs_in.color;
"
"}
"
};
// Source code for Tesselation Control Shader
static const GLchar * tesselation_control_shader[] =
{
"#version 450 core
"
"
"
"layout(vertices = 3) out;
"
"
"
"void main(void)
"
"{
"
" //Only if I am invocation 0
"
" if (gl_InvocationID == 0)
"
" {
"
" gl_TessLevelInner[0] = 5.0;
"
" gl_TessLevelOuter[0] = 5.0;
"
" gl_TessLevelOuter[1] = 5.0;
"
" gl_TessLevelOuter[2] = 5.0;
"
" }
"
"
"
" // Everybody copies their input to their input
"
" gl_out[gl_InvocationID].gl_Position =
"
" gl_in[gl_InvocationID].gl_Position;
"
"}
"
};
// Source code for tesselation evaluation shader
static const GLchar * tesselation_evaluation_shader[] =
{
"#version 450 core
"
"
"
"layout(triangles, equal_spacing, cw) in;
"
"
"
"void main(void)
"
"{
"
" gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position +
"
" gl_TessCoord.y * gl_in[1].gl_Position +
"
" gl_TessCoord.z * gl_in[2].gl_Position);
"
"}
"
};
// Create and compiler Vertex Shader
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
glCompileShader(vertex_shader);
// Create and compiler Fragment Shader
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
glCompileShader(fragment_shader);
// Create and compile tesselation control shader
control_shader = glCreateShader(GL_TESS_CONTROL_SHADER);
glShaderSource(control_shader, 1, tesselation_control_shader, NULL);
glCompileShader(control_shader);
// Create and compile tesselation evaluation shader
evaluation_shader = glCreateShader(GL_TESS_CONTROL_SHADER);
glShaderSource(evaluation_shader, 1, tesselation_control_shader, NULL);
glCompileShader(evaluation_shader);
// Create program, attach shaders to it, and link it
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glAttachShader(program, control_shader);
glAttachShader(program, evaluation_shader);
glLinkProgram(program);
// Delete shaders as program has them now
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
glDeleteShader(control_shader);
glDeleteShader(evaluation_shader);
return program;
};
class TesselationCSOne : public sb7::application
{
public:
void startup()
{
rendering_program = compile_shaders();
glCreateVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
}
void shutdown()
{
glDeleteVertexArrays(1, &vertex_array_object);
glDeleteProgram(rendering_program);
glDeleteVertexArrays(1, &vertex_array_object);
}
// Our rendering function
void render(double currentTime)
{
// Sets colour
static const GLfloat color[] = { (float)sin(currentTime) * 0.5f + 0.5f, (float)sin(currentTime) * 0.5f + 0.5f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, color);
//Tell OpenGL to draw only the outlines of the resulting triangle
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// Use program object we created for rendering
glUseProgram(rendering_program);
GLfloat attrib[] = { 1.0, 0.0, 0.0, 0.0 };/*{ (float)sin(currentTime) * 0.5f, (float)sin(currentTime) * 0.6f, 0.0f, 0.0f };*/
// Update value of input attribute 0
glVertexAttrib4fv(0, attrib);
// Draw pathes for tesselation shaders
glPatchParameteri(GL_PATCH_VERTICES, 3);
// Draw one triangle
glDrawArrays(GL_PATCHES, 0, 3);
}
private:
GLuint rendering_program;
GLuint vertex_array_object;
};
// Only instance of DECLARE_MAIN to state entry point
DECLARE_MAIN(TesselationCSOne);
Does that help?
[QUOTE=MinorMapillai;1292100]The code for the entire program is:
GLuint compile_shaders(void)
{
GLuint vertex_shader;
GLuint fragment_shader;
GLuint control_shader;
GLuint evaluation_shader;
GLuint program;
// Source code for Vertex Shader
static const GLchar * vertex_shader_source[] =
{
"#version 450 core
"
"
"
"// offset and color are input vertex attribute
"
"layout (location = 0) in vec4 offset;
"
"layout (location = 1) in vec4 color;
"
"
"
"//Declare VS_OUT as an output interface block
"
"out VS_OUT
"
"{
"
" vec4 color; //Send color to next stage
"
"}vs_out;
"
"
"
"void main(void)
"
"{
"
" //Decalre a hardcoded array of positions
"
" const vec4 vertices[3] = vec4[3](vec4(0.25, -0.25, 0.5, 1.0),
"
" vec4(-0.25, -0.25, 0.5, 1.0),
"
" vec4(0.25, 0.25, 0.5, 1.0));
"
"
"
" //Index into our array using gl_VertexID
"
" gl_Position = vertices[gl_VertexID] + offset;
"
"
"
"//color = vec4(1.0, 0.0, 0.0, 1.0);
"
"//Output fixed value for vs_color
"
"vs_out.color = color;
"
"}
"
};
// Source code for Fragment Shader
static const GLchar * fragment_shader_source[] =
{
"#version 450 core
"
"
"
"//Declare VS_OUT as an input interface block
"
"in VS_OUT
"
"{
"
" vec4 color; //Send color to next stage
"
"}fs_in;
"
"
"
"//Ouput to the framebuffer
"
"out vec4 color;
"
"
"
"void main(void)
"
"{
"
"// Simply assign the color we were given by the vertex shader to our output
"
" color = fs_in.color;
"
"}
"
};
// Source code for Tesselation Control Shader
static const GLchar * tesselation_control_shader[] =
{
"#version 450 core
"
"
"
"layout(vertices = 3) out;
"
"
"
"void main(void)
"
"{
"
" //Only if I am invocation 0
"
" if (gl_InvocationID == 0)
"
" {
"
" gl_TessLevelInner[0] = 5.0;
"
" gl_TessLevelOuter[0] = 5.0;
"
" gl_TessLevelOuter[1] = 5.0;
"
" gl_TessLevelOuter[2] = 5.0;
"
" }
"
"
"
" // Everybody copies their input to their input
"
" gl_out[gl_InvocationID].gl_Position =
"
" gl_in[gl_InvocationID].gl_Position;
"
"}
"
};
// Source code for tesselation evaluation shader
static const GLchar * tesselation_evaluation_shader[] =
{
"#version 450 core
"
"
"
"layout(triangles, equal_spacing, cw) in;
"
"
"
"void main(void)
"
"{
"
" gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position +
"
" gl_TessCoord.y * gl_in[1].gl_Position +
"
" gl_TessCoord.z * gl_in[2].gl_Position);
"
"}
"
};
// Create and compiler Vertex Shader
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
glCompileShader(vertex_shader);
// Create and compiler Fragment Shader
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
glCompileShader(fragment_shader);
// Create and compile tesselation control shader
control_shader = glCreateShader(GL_TESS_CONTROL_SHADER);
glShaderSource(control_shader, 1, tesselation_control_shader, NULL);
glCompileShader(control_shader);
// Create and compile tesselation evaluation shader
evaluation_shader = glCreateShader(GL_TESS_CONTROL_SHADER);
glShaderSource(evaluation_shader, 1, tesselation_control_shader, NULL);
glCompileShader(evaluation_shader);
// Create program, attach shaders to it, and link it
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glAttachShader(program, control_shader);
glAttachShader(program, evaluation_shader);
glLinkProgram(program);
// Delete shaders as program has them now
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
glDeleteShader(control_shader);
glDeleteShader(evaluation_shader);
return program;
};
class TesselationCSOne : public sb7::application
{
public:
void startup()
{
rendering_program = compile_shaders();
glCreateVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
}
void shutdown()
{
glDeleteVertexArrays(1, &vertex_array_object);
glDeleteProgram(rendering_program);
glDeleteVertexArrays(1, &vertex_array_object);
}
// Our rendering function
void render(double currentTime)
{
// Sets colour
static const GLfloat color[] = { (float)sin(currentTime) * 0.5f + 0.5f, (float)sin(currentTime) * 0.5f + 0.5f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, color);
//Tell OpenGL to draw only the outlines of the resulting triangle
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// Use program object we created for rendering
glUseProgram(rendering_program);
GLfloat attrib[] = { 1.0, 0.0, 0.0, 0.0 };/*{ (float)sin(currentTime) * 0.5f, (float)sin(currentTime) * 0.6f, 0.0f, 0.0f };*/
// Update value of input attribute 0
glVertexAttrib4fv(0, attrib);
// Draw pathes for tesselation shaders
glPatchParameteri(GL_PATCH_VERTICES, 3);
// Draw one triangle
glDrawArrays(GL_PATCHES, 0, 3);
}
private:
GLuint rendering_program;
GLuint vertex_array_object;
};
// Only instance of DECLARE_MAIN to state entry point
DECLARE_MAIN(TesselationCSOne);
Does that help?[/QUOTE]
Yep, but I didn’t find anything by just looking at the code. Don’t have the time to copy and compile it at the moment. Maybe somebody else finds something.