Pilpel
Pilpel

Reputation: 241

An alternative to glDrawPixels in OpenGL 3.0?

So I know that glDrawPixels is deprecated. Is there any function that does the same thing? I thought of using textures, but they are modified by the current matrix, unlike pixels that are drawn by glDrawPixels.

Upvotes: 4

Views: 3711

Answers (3)

Calvin1602
Calvin1602

Reputation: 9547

You need to draw a quad with :

  • A specific ModelViewProjection Matrix which will place it where you want (as Nicol said, there is no "current" matrix anymore)
  • A simple vertex shader which will use said Matrix to actually transform the vertices
  • A simple fragment shader which will sample the texture
  • And of course, adequate texture coordinates.

For starters, use an Identity matrix, and a mesh with X and Y coords between 0 and 1.

You might want to use a mix of http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/ and http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-11-2d-text/ (though the latter one should be improved regarding the matrix used)

Upvotes: 1

Omaha
Omaha

Reputation: 2292

You could use a fragment shader where a function of gl_FragCoord is used to sample a rectangular texture.

Alternatively, you could use a more traditional approach and just set up your transformation matrices to approximate the pixel coordinate system of your window and then draw a textured quad with your image.

Upvotes: 1

Nicol Bolas
Nicol Bolas

Reputation: 474436

I thought of using textures, but they are modified by the current matrix

The "current matrix" is deprecated in 3.0 and removed in 3.1+ as well. So if you're not using glDrawPixels, you wouldn't be using matrix functions either. So it's nothing to be concerned about.

Upvotes: 2

Related Questions