I’m having a difficult time rendering quads using glDrawArrays.
// Safe model view matrix and do transformations.
// Remember that transformation are done from bottom to top in term
// of code.So do rotations first then move etc.
// Enable blending and 2D texture.
// Check that we have at least an image to render.
if(this->imagesToRender > 0)
// Temp image.
// Image *image;
// Sort images bsaed on their texture name.
// std::sort(this->imagesToRender.begin(), this->imagesToRender.end(), Image());
// Enable arrays.
for(int i = 0; i < (int)this->texturesUsed.size(); i++)
texture = this->getTexture(*(this->texturesUsed.at(i)))->texture;
// Bind texture.
glColorPointer(4, GL_FLOAT, sizeof(ColorRGBA), this->colorList);
glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), this->textureCoordinatesList);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), this->verticesList);
glDrawArrays(GL_QUADS, 0, this->imagesToRender);
// Disable arrays.
} // Done rendering images.
// Clear textures used.
// Reset number of images to render;
this->imagesToRender = 0;
// Restore model view matrix.
// check if we have to change current projection mode
if(this->currentProjectionMode == ORTHOGRAPHIC)
// we are done with orthographic projection so enable depth test again
// Disable blending.
// Disable 2D texture.
// since we have ended a 2D scene it is NOT safe
// to call render functions
this->safeToRender = false;
I’m very knew to opengl so I have no clue what I may be missing.
They only thing that I can think of is that I’m not “pointing” to the right direction when using “gl*Pointer” functions. The idea is to render all images in one shot and keeping state changes to the minimum. I’m also trying to keep the code compatible at least with OpenGL 1.1 and later so it can be used in older video cards. Any help, tips etc is very welcome. Very eager to lean OpenGL the right way. Thank!
Some people make the mistake of not calling glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter); and they get the default state GL_LINEAR_MIPMAP_NEAREST and they don’t define the mipmaps, so the texture is considered incomplete and you just get a white texture.
An update. If I disable the color array the right number of images render but they all render in green. If I place glColor4f before glDrawArrays all the images render fine but I lose the ability to render quads with different colors. I can’t figure out whats wrong with my color array code. I store my color components, red,green, blue, alpha in a one dimensional array and they are stored as float so I have this:
glColorPointer(4, GL_FLOAT, 0, this->colorList);
I don’t understand why only some of the images are visible and others are not. Also the image that I’m rendering is 64x64, the images is a circle so the “flickering” that I’m talking about is that in some frames the border of the circle instead of being a curve is a straight line. It varies depending on the movement direction. For example if the images is moving up or down only then the top and bottom borders will suffer, if the image is moving left, right, up, down then all of the borders will be affected. This also happens with images that are rectangular.