The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.
SDL
Simple Directmedia Layer Forums
OpenGL 3 program shows only clear color
blm768
Joined: 22 May 2012
Posts: 12
Posted: Wed Aug 08, 2012 4:02 am
I've been working on an SDL2/OpenGL 3 project in the D programming language, and I've run into a really nasty bug. All of my code seems to be set up properly and runs without error messages, but no primitives are displayed on the screen.
Here's my setup code:
Code:
if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
throw new Error("Unable to initialize SDL:" ~ to!string(SDL_GetError()));
}
After that, I direct the bindings to load the OpenGL 3.2 symbols, which it does correctly.
Since my code is all nice and object-oriented, I won't post a full listing; it would take up way too much space. Instead, I'll post a commented version of the log from GLIntercept:
Code:
//Create shaders
glCreateShader(GL_VERTEX_SHADER)=1
glShaderSource(1,1,vertShaderText,vertShaderTextLen)
glCompileShader(1)
glGetShaderiv(1,GL_COMPILE_STATUS,buf)
glCreateShader(GL_FRAGMENT_SHADER)=2
glShaderSource(2,1,fragShaderText,fragShaderTextLen)
glCompileShader(2)
glGetShaderiv(2,GL_COMPILE_STATUS,buf)
glCreateProgram()=3
glAttachShader(3,1)
glAttachShader(3,2)
glLinkProgram(3)
glGetProgramiv(3,GL_LINK_STATUS,buf)
//Find uniform/attribute locations
//Extra glUseProgram() calls are for safety.
glGetUniformLocation(3,"modelview")=0
glUseProgram(3)
glGetUniformLocation(3,"projection")=1
glUseProgram(3)
glGetAttribLocation(3,"position")=0
glUseProgram(3)
glGetAttribLocation(3,"normal")=-1
glUseProgram(3)
glGetAttribLocation(3,"texCoord")=-1
//Create a texture; probably irrelevant to this code
glGenTextures(1,texId)
glBindTexture(GL_TEXTURE_2D,1)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,texData)
glGenTextures(1,01DD275C)
//Create VAO, VBO
glGenVertexArrays(1,vaoId)
glBindVertexArray(1)
glGenBuffers(1,bufId)
glBindBuffer(GL_ARRAY_BUFFER,1)
//Redundant call; actual data set later
glBufferData(GL_ARRAY_BUFFER,0,00000000,GL_STATIC_DRAW)
//Set up buffer data
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,4)
glBufferData(GL_ELEMENT_ARRAY_BUFFER,96,indexData,GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER,1)
glBufferData(GL_ARRAY_BUFFER, 48,01DC3D00,GL_STATIC_DRAW)
According to the OpenGL debugging software I used, the primitives are being processed, but they never show up on the screen. Something does seem to be strange with my projection matrix, but even hard-coding the gl_Position output to (0, 0, 0, 1), which should be right in the middle of the viewing frustum in NDC, and setting the mode to GL_POINTS does nothing.
I must have something wrong, but I just can't tell what. If someone can spot it, I'd really appreciate it.
blm768
Joined: 22 May 2012
Posts: 12
Posted: Sat Aug 18, 2012 3:49 am
Figured it out; I was setting my viewport as 0 by 0. I knew I should have initialized those variables...