Created
April 24, 2018 16:00
-
-
Save mojobojo/e688d8cae71c9f1bfd65a7a0d3015ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Render_DrawTile(f64 X, f64 Y, f64 Width, f64 Height, i32 map_width, i32 map_height, i32 TileX, i32 TileY, OpenglImage image) { | |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
GLuint TextureID = image.id; | |
GLint ProgramID = tile_draw_shader.id; | |
// NOTE: ceil prevents pixel gaps when tile edges are exactly aligned agaisnt one another | |
// doesnt always happen but will see an ocassional "shimmer" of one if there is no ceil | |
f64 TileScaleX = 1.0 / (f64)image.width * (f64)map_width; | |
f64 TileScaleY = 1.0 / (f64)image.height * (f64)map_height; | |
f64 SizeX = ceil(Width * meters_to_pixels); | |
f64 SizeY = ceil(Height * meters_to_pixels); | |
f64 PositionX = ceil(world_render_position.x + (X * meters_to_pixels) - SizeX * 0.5); | |
f64 PositionY = ceil(world_render_position.y + (Y * meters_to_pixels) - SizeY * 0.5); | |
glUseProgram(ProgramID); | |
glEnableVertexAttribArray(0); | |
glEnableVertexAttribArray(1); | |
glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertex_buffer_object); | |
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(f32), (void *)0); | |
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(f32), (void *)(2 * sizeof(f32))); | |
GLint InputTextureUniform = glGetUniformLocation(ProgramID, "Texture"); | |
glActiveTexture(GL_TEXTURE0); | |
glBindTexture(GL_TEXTURE_2D, TextureID); | |
glUniform1i(InputTextureUniform, GL_TEXTURE0); | |
GLint TileScaleUniform = glGetUniformLocation(ProgramID, "TileScale"); | |
glUniform2f(TileScaleUniform, (GLfloat)TileScaleX, (GLfloat)TileScaleY); | |
GLint TilePositionUniform = glGetUniformLocation(ProgramID, "TilePosition"); | |
glUniform2f(TilePositionUniform, (GLfloat)(TileScaleX * (GLfloat)TileX), (GLfloat)(TileScaleY * (GLfloat)TileY)); | |
GLint PositionUniform = glGetUniformLocation(ProgramID, "Position"); | |
glUniform2f(PositionUniform, (GLfloat)PositionX, (GLfloat)PositionY); | |
GLint SizeUniform = glGetUniformLocation(ProgramID, "Size"); | |
glUniform2f(SizeUniform, (GLfloat)SizeX, (GLfloat)SizeY); | |
GLint AmbientLightUniform = glGetUniformLocation(ProgramID, "AmbientLight"); | |
glUniform3fv(AmbientLightUniform, 1, ambient_light); | |
GLint TestLightPositionUniform = glGetUniformLocation(ProgramID, "TestLightPosition"); | |
//glUniform2f(TestLightPositionUniform, (GLfloat)(800.0 + 800.0 * sin(time.elapsed_time * 0.1)), (GLfloat)(window_resolution.h * 0.5)); | |
glUniform2f(TestLightPositionUniform, 0.0f, 0.0f); | |
GLint TestLightBottomUniform = glGetUniformLocation(ProgramID, "light_test_bottom"); | |
glUniform1f(TestLightBottomUniform, light_test_bottom); | |
GLint TestLightTopUniform = glGetUniformLocation(ProgramID, "light_test_top"); | |
glUniform1f(TestLightTopUniform, light_test_top); | |
GLint MVPUniform = glGetUniformLocation(ProgramID, "MVP"); | |
glUniformMatrix4fv(MVPUniform, 1, GL_FALSE, glm::value_ptr(mvp_matrix)); | |
glDrawArrays(GL_TRIANGLES, 0, 6); | |
glDisableVertexAttribArray(0); | |
glDisableVertexAttribArray(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment