Jump to content
  • Advertisement
Sign in to follow this  
Tocs1001

OpenGL Simple fullscreen quad not showing up.

This topic is 2033 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

Case Closed:

I'm an idiot, a typo in ibo.Write() caused the program to not write the indices to the IBO and thus it didn't render anything. It works now.


I've been working on a "graphics framework" (I use this term loosely), I've put OpenGL concepts into C++ classes so I can use them more easily, at any rate I decided to give them a simple test of a fullscreen quad. I init opengl to 3.1, set the clear color to blue, and start the renderloop. The quad is set to show up as white, yet I still see blue so the quad is not showing up.

First off here's my code using my framework stuff
[source lang="cpp"]//The quad, it's not there!

class ScreenQuad
{
Tocs::Graphics::VBO vbo;
Tocs::Graphics::IBO ibo;
Tocs::Graphics::VAO vao;
Tocs::Graphics::Shader QuadShader;
public:
ScreenQuad();

void Draw (Tocs::Graphics::Texture2D &texture);
};

struct CrappyVertex
{
float x,y,z;
float u,v;
};

//Crappy Fullscreen quad class, meant more as a test than a utility
ScreenQuad::ScreenQuad(void)
: vbo (4 * sizeof(CrappyVertex)),
ibo (6)
{
CrappyVertex vertices [4] = {{1,1,0,0,0},{-1,1,0,1,0},{1,-1,0,0,1},{-1,-1,0,1,1}};
vbo.Write (vertices,4,0);

unsigned short indices[6] = {0,1,2, 1,3,2};
ibo.Write (indices,6,0);

VertexFormat format;
format.AddMember ("Position",VertexType::Vec3,false);
format.AddMember ("TexCoord",VertexType::Vec2,false);

vao.Bind ();
vao.AddVBO (vbo,format);
vao.UnBind ();

ShaderCode vertcode (ShaderType::Vertex);
vertcode.CompileFromFile ("Quad.vert");
if (!vertcode.Compiled ())
{
cout << vertcode.GetCompileErrors () << endl;
return;
}

ShaderCode fragcode (ShaderType::Pixel);
fragcode.CompileFromFile ("Quad.frag");
if (!fragcode.Compiled ())
{
cout << fragcode.GetCompileErrors () << endl;
return;
}


QuadShader.SetOutput ("Color",0);

QuadShader.AddCode (vertcode);
QuadShader.AddCode (fragcode);


QuadShader.SetAttribute ("InPosition",0);
QuadShader.SetAttribute ("InTextureCoordinate",1);


QuadShader.Link ();

if (!QuadShader.Linked ())
{
cout << QuadShader.GetLinkErrors () << endl;
}
cout << "InPosition: " << QuadShader.GetAttribute ("InPosition") << endl
<< "InTextureCoordinate: " << QuadShader.GetAttribute ("InTextureCoordinate") << endl
<< "Color: " << QuadShader.GetOutput ("Color") << endl;
}


void ScreenQuad::Draw (Tocs::Graphics::Texture2D &texture)
{

QuadShader.Bind ();
//QuadShader["Texture"] = texture; //Segfaults without "Texture" uniform being used.
vao.Bind ();
ibo.Bind ();
GraphicsContext::DrawTriangles (2);
ibo.UnBind ();
vao.UnBind ();
QuadShader.UnBind ();
}[/source]

This probably wont help as much because you can't see the OpenGL, so I went inside each function and copied down the OpenGL calls so I could see more clearly the order the functions were being called. And got this.

Note: All OpenGL calls have a Debug error check, all calls are giving GL_NO_ERROR
[source lang="cpp"]glGenVertexArrays (1,&vao.ID);

glGenBuffers (1,&vbo.ID);
glBindBuffer (GL_ARRAY_BUFFER,vbo.ID);
glBufferData (GL_ARRAY_BUFFER,static_cast <GLsizeiptr> (Size),nullptr, GL_DYNAMIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER,0);

glGenBuffers (1,&ibo.ID);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);
glBufferData (GL_ELEMENT_ARRAY_BUFFER,static_cast <GLsizeiptr> (Format.GetSize () * IndiceCount),nullptr, GL_DYNAMIC_DRAW);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);

CrappyVertex vertices [4] = {{1,1,0.5,0,0},{-1,1,0.5,1,0},{1,-1,0.5,0,1},{-1,-1,0.5,1,1}};

glBindBuffer (GL_ARRAY_BUFFER,vbo.ID);
glBufferSubData (GL_ARRAY_BUFFER, 0, 20*4, vertices);
glBindBuffer (GL_ARRAY_BUFFER,0);

unsigned short indices[6] = {0,1,2, 1,3,2};

glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);
glBufferSubData (GL_ELEMENT_ARRAY_BUFFER,static_cast <GLintptr> (offset * sizeof (unsigned short)),6 * sizeof (unsigned short), static_cast <void *> (indices));
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);

glBindVertexArray (vao.ID);
glBindBuffer (GL_ARRAY_BUFFER,vbo.ID);

int index = 0;
unsigned int Offset = 0;
for (auto i = Members.begin (); i != Members.end (); ++i)
{
glEnableVertexAttribArray (index);
glVertexAttribPointer (index,(*i).GetType ().GetComponentCount (), (*i).GetType ().GetGLFormat (),(*i).IsNormalized (),Size,reinterpret_cast <GLvoid *> (Offset));
Offset += (*i).Size();
++index;
} //Gets called with GL_FLOAT 3 components, 12 bytes and GL_FLOAT 2 components, 8 bytes

glBindBuffer (GL_ARRAY_BUFFER,0);
glBindVertexArray (0);

QuadShader.ID = glCreateProgram ()

vertcode.ID = glCreateShader(GL_VERTEX_SHADER)
glShaderSource (vertcode.ID,1,&codecstr,nullptr);
glCompileShader (vertcode.ID);

fragcode.ID = glCreateShader(GL_FRAGMENT_SHADER)
glShaderSource (fragcode.ID,1,&codecstr,nullptr);
glCompileShader (fragcode.ID);

glBindFragDataLocation (QuadShader.ID,0,"Color");
glAttachShader (QuadShader.ID,vertid);
glAttachShader (QuadShader.ID,fragid);

glBindAttribLocation (QuadShader.ID,0,"InPosition");
glBindAttribLocation (QuadShader.ID,1,"InTextureCoordinate");

glLinkProgram (QuadShader.ID);

///////////////////////////////////////////////////
/////DRAW

glUseProgram (QuadShader.ID);
glBindVertexArray (vao.ID);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);
glDrawElements (GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, nullptr);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);
glBindVertexArray (0);
glUseProgram(0);[/source]
And in case the shader may be the problem here they are.
[source lang="cpp"]//Vert
#version 130
precision highp float;

in vec3 InPosition;
in vec2 InTextureCoordinate;

out vec2 TextureCoordinate;

void main()
{
TextureCoordinate = InTextureCoordinate;
gl_Position = vec4(InPosition.xy,0,1);
}

//Frag
#version 130
precision highp float;

uniform sampler2D Texture;

in vec2 TextureCoordinate;

out vec4 Color;

void main()
{
//Color = texture2D(Texture,TextureCoordinate);
Color = vec4(1,1,1,1);
} [/source]
I'm hoping it's something simple I've overlooked and someone will be able to point it out fairly quickly. Any comments, insights, insults, or other thoughts are welcome.

Thanks


EDIT: For a more complete view, I generated a log of the application startup through the first frame with gDEbugger.
[source lang="cpp"]glGetError()
wglDeleteContext(0x00010000)
wglMakeCurrent(0x6D012800, 0x00010001)
glGetString(GL_SHADING_LANGUAGE_VERSION)
glGetString(GL_VERSION)
glViewport(0, 0, 800, 800)
glGetError()
glClearColor(0, 0, 0, 0)
glGetError()
glClearDepth(1000)
glGetError()
glDisable(GL_DEPTH_TEST)
glGetError()
glDisable(GL_BLEND)
glGetError()
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
glGetError()
glGenBuffers(1, 0x0018FC2C)
glGetError()
glBindBuffer(GL_ARRAY_BUFFER, 1)
glGetError()
glBufferData(GL_ARRAY_BUFFER, 80, 0x00000000, GL_DYNAMIC_DRAW)
glGetError()
glBindBuffer(GL_ARRAY_BUFFER, 0)
glGetError()
glGenBuffers(1, 0x0018FC34)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)
glGetError()
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12, 0x00000000, GL_DYNAMIC_DRAW)
glGetError()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
glGetError()
glGenVertexArrays(1, 0x0018FC40)
glCreateProgram() [Context 2 - program 1]
glBindBuffer(GL_ARRAY_BUFFER, 1)
glGetError()
glBufferSubData(GL_ARRAY_BUFFER, 0, 80, 0x0018FAA0)
glGetError()
glBindBuffer(GL_ARRAY_BUFFER, 0)
glGetError()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)
glGetError()
glBindVertexArray(1)

/////////////HERE! Is where the missing glBufferSubData () call should go.

glGetError()
glBindBuffer(GL_ARRAY_BUFFER, 1)
glGetError()
glEnableVertexAttribArray(0)
glGetError()
glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 20, 0x00000000)
glGetError()
glEnableVertexAttribArray(1)
glGetError()
glVertexAttribPointer(1, 2, GL_FLOAT, FALSE, 20, 0x0000000C)
glGetError()
glBindBuffer(GL_ARRAY_BUFFER, 0)
glGetError()
glBindVertexArray(0)
glGetError()
glCreateShader(GL_VERTEX_SHADER) [Context 2 - Shader 2: source code is not available]
glGetError()
glShaderSource(2, 1, 0x0018F5C4, 0x00000000) [Context 2 - shader 2]
glGetError()
glCompileShader(2) [Context 2 - shader 2]
glGetError()
glGetShaderiv(2, GL_COMPILE_STATUS, 0x0018F7E0) [Context 2 - shader 2]
glGetError()
glCreateShader(GL_FRAGMENT_SHADER) [Context 2 - Shader 3: source code is not available]
glGetError()
glShaderSource(3, 1, 0x0018F5C4, 0x00000000) [Context 2 - shader 3]
glGetError()
glCompileShader(3) [Context 2 - shader 3]
glGetError()
glGetShaderiv(3, GL_COMPILE_STATUS, 0x0018F7E0) [Context 2 - shader 3]
glGetError()
glBindFragDataLocation(1, 0, 0x0018F7DC)
glGetError()
glAttachShader(1, 2) [Context 2 - program 1][Context 2 - shader 2]
glAttachShader(1, 3) [Context 2 - program 1: shader 2][Context 2 - shader 3]
glBindAttribLocation(1, 0, InPosition) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glBindAttribLocation(1, 1, InTextureCoordinate) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glLinkProgram(1) [Context 2 - program 1: shader 2, shader 3]
glGetObjectParameterivARB(1, GL_LINK_STATUS, 0x0018F7D0) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glGetObjectParameterivARB(1, GL_VALIDATE_STATUS, 0x0018F7D0) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glGetObjectParameterivARB(1, GL_ACTIVE_UNIFORMS, 0x0018F7C4) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glGetProgramiv(1, GL_INFO_LOG_LENGTH, 0x0018F7C8) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glGetProgramInfoLog(1, 1, 0, ) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glGetFragDataLocation(1, 0x0018F7DC)
glGetAttribLocation(1, InTextureCoordinate) [Context 2 - program 1: shader 2, shader 3]
glGetAttribLocation(1, InPosition) [Context 2 - program 1: shader 2, shader 3]
glDeleteShader(3) [Context 2 - shader 3]
glGetError()
glDeleteShader(2) [Context 2 - shader 2]
glGetError()
glGenTextures(1, {0})
glBindTexture(GL_TEXTURE_2D, 1) [Context 2 - Texture 1: No preview available]
glGetError()
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) [Context 2 - Texture 1: No preview available]
glGetError()
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) [Context 2 - Texture 1: No preview available]
glGetError()
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) [Context 2 - Texture 1: No preview available]
glGetError()
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) [Context 2 - Texture 1: No preview available]
glGetError()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 100, 100, 0, GL_RED, GL_UNSIGNED_SHORT, 0x00000000) [Context 2 - Texture 1: No preview available]
glGetError()
glBindTexture(GL_TEXTURE_2D, 0)
glClearColor(0.39215687, 0.58431375, 0.92941177, 1)
glGetError()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glGetError()
glUseProgram(1) [Context 2 - program 1: shader 2, shader 3]
glGetError()
glBindVertexArray(1)
glGetError()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)
glGetError()
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0x00000000)
glGetError()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
glGetError()
glBindVertexArray(0)
glGetError()
glUseProgram(0) [Context 2 - program 0]
glGetError()
wglSwapBuffers(0x6D012800) [/source] Edited by Tocs1001

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!