Basics of drawing in 2d with OpenGL 3 shaders

Posted by davidism on Game Development See other posts from Game Development or by davidism
Published on 2012-03-12T17:52:39Z Indexed on 2012/03/18 18:25 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

I am new to OpenGL 3 and graphics programming, and want to create some basic 2d graphics. I have the following scenario of how I might go about drawing a basic (but general) 2d rectangle. I'm not sure if this is the correct way to think about it, or, if it is, how to implement it.

In my head, here's how I imagine doing it:

  1. t = make_rectangle(width, height)
    • build general VBO, centered at 0, 0
  2. optionally: t.set_scale(2)
  3. optionally: t.set_angle(30)
  4. t.draw_at(x, y)
    • calculates some sort of scale/rotate/translate matrix (or matrices), passes the VBO and the matrix to a shader program
  5. Something happens to clip the world to the view visible on screen.

I'm really unclear on how 4 and 5 will work. The main problem is that all the tutorials I find either: use fixed function pipeline, are for 3d, or are unclear how to do something this "simple".

Can someone provide me with either a better way to think of / do this, or some concrete code detailing performing the transformations in a shader and constructing and passing the data required for this shader transformation?

© Game Development or respective owner

Related posts about opengl

Related posts about 2d