Vec4 totalOffset = vec4(offset.x, offset.y, 0.0, 0.0) Let’s look at our vertex shader offset_vertex.glsl This is pretty powerful stuff, as we can let the GPU do a lot of the processing by using shader programs, and passing them attributes to control the overall affect that we want. This almost feels like Uber-CSS over the top of HTML. The clever thing about this is, we won’t be changing the vertex data stored in the buffer, but will instead be manipulating it with Fragment and Vertex shaders. With this code, we are going to take our original triangle, and we will make it move around a bit, and also change colour at the same time. This also comes from the “OpenGL’s Moving Triangle” section of the Learning Modern 3D Graphics Programming online book. We’ll be look at the example show_triangle_vert_frag_offset.rb, which can be run from the command bin/triangle_vert_frag_offset. While on the surface this can seem overtly complicated, it actually becomes the basis of a powerful OpenGL achitecture to enable you to leverage the GPU is a variety of very interesting ways without having to rely on the CPU. In Part 2 we drew a triangle using a Vertex Buffer, and some basic shaders. JRuby, LWJGL & OpenGL – Getting Started with Shaders
0 Comments
Leave a Reply. |