Skip to content

Commit

Permalink
image rendering works now
Browse files Browse the repository at this point in the history
  • Loading branch information
Randall Smith committed Mar 23, 2017
1 parent a691329 commit be48dd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions image_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ out vec4 fragment_color;

void main(void) {
fragment_color = texture(texture_sampler, coord);
// fragment_color = vec4(coord[0], coord[1], 0.0, 1.0);
}
4 changes: 2 additions & 2 deletions image_vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#version 330

in vec4 vertex_position;
in vec3 vertex_position;
in vec2 texture_coordinate;
out vec2 coord;

void main(void)
{
gl_Position = vertex_position;
gl_Position = vec4(vertex_position, 1.0);
coord = texture_coordinate;
}
25 changes: 14 additions & 11 deletions image_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ def __init__(self, fragment_shader_path, vertex_shader_path):
self.fragment_shader_path = fragment_shader_path
self.vertex_shader_path = vertex_shader_path
self.vertex_data = np.array([
-1.0, -1.0, 0.0, 1.0,
1.0, -1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
-1.0, 1.0, 0.0, 1.0
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, 1.0, 0.0
]).astype(dtype=np.float32, order='C')
self.vertex_byte_count = ArrayDatatype.arrayByteCount(self.vertex_data)
self.index_data = np.array([
0, 1, 2, 3
0, 1, 2, 0, 2, 3
]).astype(dtype=np.uint32, order='C')
self.index_byte_count = ArrayDatatype.arrayByteCount(self.index_data)
self.texture_data = np.array([
0.0, 0.0,
1.0, 0.0,
1.0, 0.0,
0.0, 0.0
1.0, 1.0,
0.0, 1.0
]).astype(dtype=np.float32, order='C')
self.texture_byte_count = ArrayDatatype.arrayByteCount(self.texture_data)
self.image_loaded = False
Expand Down Expand Up @@ -97,18 +97,17 @@ def initialize(self):
self.vertex_location = self.program.attribute_location(
'vertex_position')
glBindBuffer(GL_ARRAY_BUFFER, self.vbo_id[0])
glVertexAttribPointer(self.vertex_location, 4,
glVertexAttribPointer(self.vertex_location, 3,
GL_FLOAT, GL_FALSE, 0, None)
glEnableVertexAttribArray(self.vertex_location)
# Setup the texture data in VBO.
glBindBuffer(GL_ARRAY_BUFFER, self.vbo_id[1])
self.texture_location = self.program.attribute_location(
'texture_coordinate')
glBindBuffer(GL_ARRAY_BUFFER, self.vbo_id[1])
glVertexAttribPointer(self.texture_location, 2,
GL_FLOAT, GL_FALSE, 0, None)
glEnableVertexAttribArray(self.texture_location)


self.texture_sampler_location = self.program.uniform_location(
'texture_sampler')

Expand All @@ -119,6 +118,10 @@ def render(self, width, height):
glViewport(0, 0, width, height)
glClearColor(0.0, 0.0, 0.0, 0.0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glDepthFunc(GL_LESS)

Expand Down Expand Up @@ -150,4 +153,4 @@ def render(self, width, height):
glBindVertexArray(self.vao_id)

# Draw the triangles.
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, None)
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None)

0 comments on commit be48dd7

Please sign in to comment.