

This is where the perspective transformation takes place, which projects vertices with a 3D world position onto your 2D screen! It also passes important attributes like color and texture coordinates further down the pipeline.Īfter the input vertices have been transformed, the graphics card will form triangles, lines or points out of them. The vertex shader is a small program running on your graphics card that processes every one of these input vertices individually. Commonly used attributes are 3D position in the world and texture coordinates. Each of these points is stored with certain attributes and it's up to you to decide what kind of attributes you want to store. It all begins with the vertices, these are the points from which shapes like triangles will later be constructed.


I'll explain these steps with help of the following illustration. The graphics pipeline covers all of the steps that follow each other up on processing the input data to get to the final output image. To top that all, the exercises at the end of this chapter will show you the sheer amount of control you have over the rendering process by doing things the modern way! That inevitably means that you'll be thrown in the deep, but once you understand the essentials, you'll see that doing things the hard way doesn't have to be so difficult after all. Vertex shader: (replace the colors with whatever you needed !) #version 330Ĭonst vec4 wireframeColor = vec4(1.0f, 0.0f, 0.0f, 1.0f) Ĭonst vec4 fillColor = vec4(1.0f, 1.0f, 1.0f, 1.0f) įloat d = min(, min(, learning OpenGL, you've decided that you want to do all of the hard work yourself. Vec2 scale = vec2(500.0f, 500.0f) // scaling factor to make 'd' in frag shader big enough to show something Layout(triangle_strip, max_vertices = 3) out Vdata.position = projection * mv * position Vertex shader: (replace the inputs with whatever you use to pass in vertex data an m, v and p matrices) #version 330 Here is my own stab at it, basically a port of their implementation for OpenGL 3.3, limited to triangle primitives: It also provides a sample implementation of the simplest technique in GLSL. This paper has all the relevant theory : Shader-Based wireframe drawing. This would work for OpenGL 3.2 and above as part of the core functionality, or for OpenGL 2.1 with extension GL_EXT_geometry_shader4. A more modern approach would be to implement this via geometry shaders.
