[retro-gtk/wip/aplazas/gl-display] draw the texture
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display] draw the texture
- Date: Tue, 14 Nov 2017 09:02:39 +0000 (UTC)
commit 9c2c79dda1f80f2457d0e1d60de4a9f877faa895
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Nov 14 09:24:34 2017 +0100
draw the texture
retro-gtk/retro-gl-display-vertex.glsl | 11 ++++++++++-
retro-gtk/retro-gl-display.c | 7 +++++++
2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display-vertex.glsl b/retro-gtk/retro-gl-display-vertex.glsl
index c7b54e8..529d345 100644
--- a/retro-gtk/retro-gl-display-vertex.glsl
+++ b/retro-gtk/retro-gl-display-vertex.glsl
@@ -5,8 +5,17 @@ in vec2 texture_coordinates;
out vec2 texture_coordinates_frag;
+uniform float relative_aspect_ratio;
+
void main ()
{
texture_coordinates_frag = texture_coordinates;
- gl_Position = vec4 (position, 0.0, 1.0);
+ if (relative_aspect_ratio > 1.0f)
+ gl_Position = vec4 (position.x / relative_aspect_ratio,
+ position.y,
+ 0.0, 1.0);
+ else
+ gl_Position = vec4 (position.x,
+ position.y * relative_aspect_ratio,
+ 0.0, 1.0);
}
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index e307814..13b693c 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -173,6 +173,7 @@ retro_gl_display_render (RetroGLDisplay *self)
gdouble x = 0.0;
gdouble y = 0.0;
GLenum filter;
+ GLint relative_aspect_ratio;
g_return_val_if_fail (self != NULL, FALSE);
@@ -209,6 +210,12 @@ retro_gl_display_render (RetroGLDisplay *self)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ relative_aspect_ratio = glGetUniformLocation (self->shader_program, "relative_aspect_ratio");
+ glUniform1f (relative_aspect_ratio,
+ (gfloat) gtk_widget_get_allocated_width (GTK_WIDGET (self)) /
+ (gfloat) gtk_widget_get_allocated_height (GTK_WIDGET (self)) /
+ self->aspect_ratio);
+
glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]