简体   繁体   中英

OpenGL 3.2 2D rendering issues

rendering artifact http://byte-werx.com/rendering-artifact.png

When I create two sprite batches and attempt to draw twice on the same frame half of my screen (or thereabouts) gets "lost"; this happens regardless of the position of the little campfire sprite.

When rendering in wireframe mode the same results occur so it does not appear that a giant black polygon is getting drawn and overriding the under laying tilemap.

This is the code used to initialize OpenGL:

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnableClientState(GL_VERTEX_ARRAY);
glActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE0);
glDepthRange(0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glDisable(GL_DITHER);
glClearDepth(1.0f);
glEnable(GL_CW);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I have uploaded the relevant code here: download

SDL2 is used for window creation and context management, however I do not use anything else from SDL.

Resolved the issue, I was not unbinding the array/element buffers after calling glDrawElements.

Had to put this after glDrawElements:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM