# OpenGL/SDL2 window stopped rendering [closed]

I have been working on a game engine for a couple of days now and I've had it rendering a colourful cube and playing sounds in OGG format, but, after refactoring my code-base to make things easier; it no longer displays the cube! (This happened when I put the shader program and methods into a seperate class)

What could be the problem?

OpenGL/SDL2 context class:

class RenderContext{
public:
RenderContext();
~RenderContext();

void draw();

int16_t good;

};


BufferObject class

class BufferObject{
public:
BufferObject(){};

template<class Type>
BufferObject(GLenum bufferTarget, vector<Type> &bufferData){
target = bufferTarget;

glGenBuffers(1, &buffer);
glBindBuffer(bufferTarget, buffer);
glBufferData(bufferTarget, bufferData.size(), bufferData.data(), GL_STATIC_DRAW);
glBindBuffer(bufferTarget, 0);

glGetBufferParameteriv(bufferTarget, GL_BUFFER_SIZE, &size);

good = true;
}

void bind(){
glBindBuffer(target, buffer);
}

void unbind(){
glBindBuffer(target, 0);
}

void draw(GLenum drawMode){
switch(target){
case GL_ELEMENT_ARRAY_BUFFER:
glDrawElements(drawMode, size/sizeof(uint16_t), GL_UNSIGNED_SHORT, 0);
return;
break;

case GL_ARRAY_BUFFER:
glDrawArrays(drawMode, 0, size/sizeof(float));
return;
break;

default:
return;
}
}

~BufferObject(){
glDeleteBuffers(1, &buffer);
}

bool good;

private:
uint32_t target;
uint32_t buffer;
int size;
};


class ShaderProgram{
public:
}

ShaderProgram(const char *vsPath, const char *fsPath){

const char *source = vsSource.c_str();
source = fsSource.c_str();

if(compileStat == 0){
char BUFFER[256];
cerr << "-!- Error compiling vertex shader: " << BUFFER << endl;
good = false;
return;
}

if(compileStat == 0){
char BUFFER[256];
cerr << "-!- Error compiling fragment shader: " << BUFFER << endl;
good = false;
return;
}

program = glCreateProgram();

cerr << "-!- Error linking program." << endl;
good = false;
return;
}

good = true;
}

void getUniform(uint32_t &location, const char *uniformName){
location = glGetUniformLocation(program, uniformName);
assert(location != 0xFFFFFFFF);
}

void bind(){
glUseProgram(program);
}

void unbind(){
glUseProgram(0);
}

glDeleteProgram(program);
glUseProgram(0);
}

bool good;
uint32_t program;
};


Then the ShaderProgram is used like so in the drawing loop:

**first init:**
VBO = new BufferObject(GL_ARRAY_BUFFER, coord);
IBO = new BufferObject(GL_ELEMENT_ARRAY_BUFFER, indicies);

**then:**
program->bind();

glUniformMatrix4fv(projMatrixLoc, 1, GL_FALSE, &projMatrix[0][0]);
glUniformMatrix4fv(viewMatrixLoc, 1, GL_FALSE, &viewMatrix[0][0]);
glUniformMatrix4fv(modelMatrixLoc, 1, GL_FALSE, &modelMatrix[0][0]);

glEnableVertexAttribArray(0);

VBO->bind();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
VBO->unbind();

IBO->bind();
IBO->draw(GL_TRIANGLES);
IBO->unbind();

glDisableVertexAttribArray(0);

program->unbind();


## closed as too localized by MichaelHouse♦, Josh♦, Anko, bummzack, msellApr 25 '13 at 8:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• This is why you should use a version control tool ;) – Alex Apr 18 '13 at 10:28

It's hard to tell from just that code. How do you use ShaderProgram during the actual drawing process? The only thing that I can think of from that code (assuming you aren't getting shader compile/link errors) is that maybe an instance of the ShaderProgram object is going out of scope and deleting the program prematurely.

EDIT:

 glBufferData(bufferTarget, bufferData.size(), bufferData.data(), GL_STATIC_DRAW);


bufferData.size() is the number of elements in the vector, not the size in bytes. You are probably not allocating enough space for all your data. Change it to:

glBufferData(bufferTarget, bufferData.size()*sizeof(Type), ...


Not sure how valid the sizeof(Type) thing is but you can always add an extra parameter or something if that doesn't work.

• Edited, it will be something silly like that. – CoffeeandCode Apr 18 '13 at 10:40
• I can't see anything obviously wrong. Try hacking a glGetError call in before and after your drawing code and see if that gives us any clues. – Lewis Wakeford Apr 18 '13 at 11:22