Moondust-Project
Moondust-Project copied to clipboard
[Engine] Implement the glDraw lua api function
This function allows to draw various polygonal shapes by using OpenGL calls (or surrogates of them in software rendering mode), is widely used in many lua libraries created for LunaLua.
Copy of @Bluenaxela 's message:
@Wohlstand So.... if this helps you understand glDraw.... if one strips away all the helper code that does both conversion of data formats and GL state management, it comes down to the following pseudocode. In it, every single "somethingParameter" value can be customized by Lua, and everything except vertexCoordsParameter is optional (affecting whether or not some gl calls happpen, or has a default value).
/* optional */ glBindTexture(GL_TEXTURE_2D, textureParameter);
/* optional */ glUseProgram(shaderParameter);
// If shaderParameter was set, also call "glUniform..."/"glAttribute..." functions for each passed in
/* optional */ glColor4f(colorParameters...);
if (sceneCoordsParameter) {
// Use glMatrixMode and glTranslatef to translate the GL_MODELVIEW matrix to allow vertex coordinates to be in terms of scene coordinates
}
glVertexPointer(2, GL_FLOAT, 0, vertexCoordsParameter);
/* optional */ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordsParameter);
/* optional */ glColorPointer(4, GL_FLOAT, 0, vertexColorParameter);
glDrawArrays(drawTypeParameter, 0, vertexCount);