Hello,
i want to render simple primatives in a view port using glDrawElements on VBO, but for hours i am now stuck with an empty viewport, where nothing is drawn at all.
I dont receive any error messages or have any other problems, but the viewport simple stays empty.
The test code i am using now looks similar to this:
#Used Shaders
const char* defaultFragmentShader = "\
varying lowp vec3 primaryColor;\
void main (void)\
{\
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);\
}";
const char* defaultVertexShader = "\
attribute highp vec4 position;\
attribute lowp vec3 color;\
uniform mediump mat4 matrix;\
varying vec3 primaryColor; \
void main(void)\
{\
primaryColor = color;\
gl_Position = matrix * position;\
}";
#Shader program is created, linked, and referenced to the attributes and uniforms are acquired after linking
#Prepare Viewport
glViewport(this->x, this->y, this->width, this->height);
glScissor(this->x, this->y, this->width, this->height);
glClearColor(this->red, this->green, this->blue, this->alpha);
glClear(GL_COLOR_BUFFER_BIT);
#set shader program
glUseProgram(this->program);
//Generate Buffer index
glGenBuffers(3, (GLuint*) this->bufferIndex);
if(glIsBuffer(this->bufferIndex[0]) == false) throw "Could not generate Vertex Buffer!";
if(glIsBuffer(this->bufferIndex[1]) == false) throw "Could not generate Color Buffer!";
if(glIsBuffer(this->bufferIndex[2]) == false) throw "Could not generate Index Buffer!";
#Load vertex position, color and index information into the buffers ,
glBindBuffer(GL_ARRAY_BUFFER, this->bufferIndex[0]); //Set first index to be Array Buffer (sets it also to the active VertexBuffer)
if (!OGLESTools::TestEGLError("glBindBuffer")){ throw "Binding VOB failed!"; }
glBufferData(GL_ARRAY_BUFFER, this->shaderProgram->getVertexSize() * sizeof(GL_FLOAT) * this->nVertices, this->vertices, GL_STATIC_DRAW); //Loads numVertices from *vertexSource into the active VertexBuffer
if (!OGLESTools::TestEGLError("glBufferData")){ throw "Loading VOB failed!"; }
glVertexAttribPointer( this->shaderProgram->getVertexLocation() , this->shaderProgram->getVertexSize() , GL_FLOAT, GL_FALSE, 0, 0 );
glBindBuffer(GL_ARRAY_BUFFER, this->bufferIndex[1]); //Set first index to be Array Buffer (sets it also to the active VertexBuffer)
if (!OGLESTools::TestEGLError("glBindBuffer")){ throw "Binding VOB failed!"; }
glBufferData(GL_ARRAY_BUFFER, this->shaderProgram->getColorSize() * sizeof(GL_FLOAT) * this->nVertices, this->color, GL_STATIC_DRAW); //Loads numVertices from *vertexSource into the active VertexBuffer
if (!OGLESTools::TestEGLError("glBufferData")){ throw "Loading VOB failed!"; }
glVertexAttribPointer( this->shaderProgram->getColorLocation() , this->shaderProgram->getColorSize() , GL_FLOAT, GL_FALSE, 0, 0 );
//Prepare Vertex Index Buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->bufferIndex[2]); //Set first index to be Array Buffer (sets it also to the active VertexBuffer)
if (!OGLESTools::TestEGLError("glBindBuffer")){ throw "Binding VOB failed!"; }
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * this->nIndexes, this->indexes, GL_STATIC_DRAW); //Load the vertex index information
if (!OGLESTools::TestEGLError("glBufferData")){ throw "Loading VOB failed!"; }
#enable the Vertex Position and Color buffer
glEnableVertexAttribArray( this->shaderProgram->getVertexLocation() );
if (!OGLESTools::TestEGLError("glEnableVertexAttribArray")){ throw "glEnableVertexAttribArray failed!"; }
//glBindBuffer(GL_ARRAY_BUFFER, this->bufferIndex[1]); //Set first index to be Array Buffer (sets it also to the active VertexBuffer)
// if (!OGLESTools::TestEGLError("glBindBuffer")){ throw "Binding VOB failed!"; }
glEnableVertexAttribArray( this->shaderProgram->getColorLocation() );
if (!OGLESTools::TestEGLError("glEnableVertexAttribArray")){ throw "glEnableVertexAttribArray failed!"; }
#Call glDrawElements ( there are three vertex defined, with position,color, index )
glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_SHORT, (void*) 0);
glDisableVertexAttribArray( this->shaderProgram->getVertexLocation() );
glDisableVertexAttribArray( this->shaderProgram->getColorLocation() );
#Flip Buffers
eglSwapBuffers(eglDisplay, eglSurface);
Does this look alright? Anyone has an idea what could be wrong?
Thanks!