shithub: cstory

Download patch

ref: d8aec418f9a72e51897a5256cdd78ee56e9053d0
parent: 67b3143ed6269a281541381e9ef6dfb3289de853
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Aug 1 09:11:55 EDT 2019

OpenGL: Use a struct for defining 2D coordinates

Makes the code a bit more readable

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -25,10 +25,16 @@
 	unsigned int height;
 } Backend_Glyph;
 
+typedef struct Coordinate2D
+{
+	GLfloat x;
+	GLfloat y;
+} Coordinate2D;
+
 typedef struct VertexBuffer
 {
-	GLfloat vertexes[4][2];
-	GLfloat texture_coordinates[4][2];
+	Coordinate2D vertexes[4];
+	Coordinate2D texture_coordinates[4];
 } VertexBuffer;
 
 static SDL_Window *window;
@@ -281,23 +287,23 @@
 	// Draw framebuffer to screen
 	glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id);
 
-	vertex_buffer.texture_coordinates[0][0] = 0.0f;
-	vertex_buffer.texture_coordinates[0][1] = 1.0f;
-	vertex_buffer.texture_coordinates[1][0] = 1.0f;
-	vertex_buffer.texture_coordinates[1][1] = 1.0f;
-	vertex_buffer.texture_coordinates[2][0] = 1.0f;
-	vertex_buffer.texture_coordinates[2][1] = 0.0f;
-	vertex_buffer.texture_coordinates[3][0] = 0.0f;
-	vertex_buffer.texture_coordinates[3][1] = 0.0f;
+	vertex_buffer.texture_coordinates[0].x = 0.0f;
+	vertex_buffer.texture_coordinates[0].y = 1.0f;
+	vertex_buffer.texture_coordinates[1].x = 1.0f;
+	vertex_buffer.texture_coordinates[1].y = 1.0f;
+	vertex_buffer.texture_coordinates[2].x = 1.0f;
+	vertex_buffer.texture_coordinates[2].y = 0.0f;
+	vertex_buffer.texture_coordinates[3].x = 0.0f;
+	vertex_buffer.texture_coordinates[3].y = 0.0f;
 
-	vertex_buffer.vertexes[0][0] = -1.0f;
-	vertex_buffer.vertexes[0][1] = -1.0f;
-	vertex_buffer.vertexes[1][0] = 1.0f;
-	vertex_buffer.vertexes[1][1] = -1.0f;
-	vertex_buffer.vertexes[2][0] = 1.0f;
-	vertex_buffer.vertexes[2][1] = 1.0f;
-	vertex_buffer.vertexes[3][0] = -1.0f;
-	vertex_buffer.vertexes[3][1] = 1.0f;
+	vertex_buffer.vertexes[0].x = -1.0f;
+	vertex_buffer.vertexes[0].y = -1.0f;
+	vertex_buffer.vertexes[1].x = 1.0f;
+	vertex_buffer.vertexes[1].y = -1.0f;
+	vertex_buffer.vertexes[2].x = 1.0f;
+	vertex_buffer.vertexes[2].y = 1.0f;
+	vertex_buffer.vertexes[3].x = -1.0f;
+	vertex_buffer.vertexes[3].y = 1.0f;
 
 	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -395,23 +401,23 @@
 	const GLfloat vertex_top = (y * (2.0f / destination_surface->height)) - 1.0f;
 	const GLfloat vertex_bottom = ((y + (rect->bottom - rect->top)) * (2.0f / destination_surface->height)) - 1.0f;
 
-	vertex_buffer.texture_coordinates[0][0] = texture_left;
-	vertex_buffer.texture_coordinates[0][1] = texture_top;
-	vertex_buffer.texture_coordinates[1][0] = texture_right;
-	vertex_buffer.texture_coordinates[1][1] = texture_top;
-	vertex_buffer.texture_coordinates[2][0] = texture_right;
-	vertex_buffer.texture_coordinates[2][1] = texture_bottom;
-	vertex_buffer.texture_coordinates[3][0] = texture_left;
-	vertex_buffer.texture_coordinates[3][1] = texture_bottom;
+	vertex_buffer.texture_coordinates[0].x = texture_left;
+	vertex_buffer.texture_coordinates[0].y = texture_top;
+	vertex_buffer.texture_coordinates[1].x = texture_right;
+	vertex_buffer.texture_coordinates[1].y = texture_top;
+	vertex_buffer.texture_coordinates[2].x = texture_right;
+	vertex_buffer.texture_coordinates[2].y = texture_bottom;
+	vertex_buffer.texture_coordinates[3].x = texture_left;
+	vertex_buffer.texture_coordinates[3].y = texture_bottom;
 
-	vertex_buffer.vertexes[0][0] = vertex_left;
-	vertex_buffer.vertexes[0][1] = vertex_top;
-	vertex_buffer.vertexes[1][0] = vertex_right;
-	vertex_buffer.vertexes[1][1] = vertex_top;
-	vertex_buffer.vertexes[2][0] = vertex_right;
-	vertex_buffer.vertexes[2][1] = vertex_bottom;
-	vertex_buffer.vertexes[3][0] = vertex_left;
-	vertex_buffer.vertexes[3][1] = vertex_bottom;
+	vertex_buffer.vertexes[0].x = vertex_left;
+	vertex_buffer.vertexes[0].y = vertex_top;
+	vertex_buffer.vertexes[1].x = vertex_right;
+	vertex_buffer.vertexes[1].y = vertex_top;
+	vertex_buffer.vertexes[2].x = vertex_right;
+	vertex_buffer.vertexes[2].y = vertex_bottom;
+	vertex_buffer.vertexes[3].x = vertex_left;
+	vertex_buffer.vertexes[3].y = vertex_bottom;
 
 	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -453,14 +459,14 @@
 	const GLfloat vertex_top = (rect->top * (2.0f / surface->height)) - 1.0f;
 	const GLfloat vertex_bottom = (rect->bottom * (2.0f / surface->height)) - 1.0f;
 
-	vertex_buffer.vertexes[0][0] = vertex_left;
-	vertex_buffer.vertexes[0][1] = vertex_top;
-	vertex_buffer.vertexes[1][0] = vertex_right;
-	vertex_buffer.vertexes[1][1] = vertex_top;
-	vertex_buffer.vertexes[2][0] = vertex_right;
-	vertex_buffer.vertexes[2][1] = vertex_bottom;
-	vertex_buffer.vertexes[3][0] = vertex_left;
-	vertex_buffer.vertexes[3][1] = vertex_bottom;
+	vertex_buffer.vertexes[0].x = vertex_left;
+	vertex_buffer.vertexes[0].y = vertex_top;
+	vertex_buffer.vertexes[1].x = vertex_right;
+	vertex_buffer.vertexes[1].y = vertex_top;
+	vertex_buffer.vertexes[2].x = vertex_right;
+	vertex_buffer.vertexes[2].y = vertex_bottom;
+	vertex_buffer.vertexes[3].x = vertex_left;
+	vertex_buffer.vertexes[3].y = vertex_bottom;
 
 	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer.vertexes), &vertex_buffer);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -587,23 +593,23 @@
 
 	glUniform4f(program_glyph_uniform_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f);
 
-	vertex_buffer.texture_coordinates[0][0] = 0.0f;
-	vertex_buffer.texture_coordinates[0][1] = 0.0f;
-	vertex_buffer.texture_coordinates[1][0] = 1.0f;
-	vertex_buffer.texture_coordinates[1][1] = 0.0f;
-	vertex_buffer.texture_coordinates[2][0] = 1.0f;
-	vertex_buffer.texture_coordinates[2][1] = 1.0f;
-	vertex_buffer.texture_coordinates[3][0] = 0.0f;
-	vertex_buffer.texture_coordinates[3][1] = 1.0f;
+	vertex_buffer.texture_coordinates[0].x = 0.0f;
+	vertex_buffer.texture_coordinates[0].y = 0.0f;
+	vertex_buffer.texture_coordinates[1].x = 1.0f;
+	vertex_buffer.texture_coordinates[1].y = 0.0f;
+	vertex_buffer.texture_coordinates[2].x = 1.0f;
+	vertex_buffer.texture_coordinates[2].y = 1.0f;
+	vertex_buffer.texture_coordinates[3].x = 0.0f;
+	vertex_buffer.texture_coordinates[3].y = 1.0f;
 
-	vertex_buffer.vertexes[0][0] = vertex_left;
-	vertex_buffer.vertexes[0][1] = vertex_top;
-	vertex_buffer.vertexes[1][0] = vertex_right;
-	vertex_buffer.vertexes[1][1] = vertex_top;
-	vertex_buffer.vertexes[2][0] = vertex_right;
-	vertex_buffer.vertexes[2][1] = vertex_bottom;
-	vertex_buffer.vertexes[3][0] = vertex_left;
-	vertex_buffer.vertexes[3][1] = vertex_bottom;
+	vertex_buffer.vertexes[0].x = vertex_left;
+	vertex_buffer.vertexes[0].y = vertex_top;
+	vertex_buffer.vertexes[1].x = vertex_right;
+	vertex_buffer.vertexes[1].y = vertex_top;
+	vertex_buffer.vertexes[2].x = vertex_right;
+	vertex_buffer.vertexes[2].y = vertex_bottom;
+	vertex_buffer.vertexes[3].x = vertex_left;
+	vertex_buffer.vertexes[3].y = vertex_bottom;
 
 	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);