Advertisement Jump to content
Sign in to follow this  

Converting to OpenGL 4

This topic is 676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use an OpenTK GLcontrol as a faster alternative to GDI+ for displaying images and I would like to convert the old deprecated code to OpenGL 4 but I'm having trouble adapting code samples in guides I have found to my needs so would anyone kindly show me how to convert this:

GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, rez.Width, rez.Height, PixelFormat.Bgr, PixelType.UnsignedByte, currentframe);
GL.Ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
GL.BindTexture(TextureTarget.Texture2D, tex);
GL.TexCoord2(0.0f, 1.0f);
GL.Vertex2(-1.0f, -1.0f);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex2(1.0f, 1.0f);
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(-1.0f, 1.0f);

Share this post

Link to post
Share on other sites

There is sadly not but that is what makes "modern" graphics so flexible. You need to manage anything by your own from vertex management to the render/processing pipeline.

I did need a small class for debug code output in the past but even that needed a min of a vertex buffer to tell the graphics where are the pixel areas I want to write to, a texture holding thatever has to be shown (text in my case) and at least to shaders (vertex and fragment) to bring whatever up to the screen.

Matrix calculations are now no longer made by GL since you need to roll your own or use a library as mentioned because you need to transform every pixel by the shader for getting expected results. Passing an identity matrix does not do what you might expect here so calculating ortho or projection view is needed. OpenTK has this capability already so dont worry about that, just calc a matrix and load it into your shader.

Anything between begin and end needs to be put into a VBO/VAO once so making a general setup here saves you a lot of render time.

It might look like a mountain of work but it isnt and it is worth it

Share this post

Link to post
Share on other sites

If you only want to get a big 2d pixel array to the screen your current code is just fine from a performance standpoint.

With OpenGL or D3D11 you can't access texture data directly and always neet to use a api copy command to get data into a texture before you can then get that texture onto the screen.

Only D3D12 and Vulkan give you the abbility to draw directly from client memory to the screen.

If you do blitting, like put you scene together by drawing many square images (sprites). Then it may be already worth to consider a more modern approche.

Edit: I hate forums that fuck up formating if your don't use javascript. -_-

Edited by Osbios

Share this post

Link to post
Share on other sites

I'd love to be able to use Vulcan but from what I've read its difficult even for an experienced graphics programmer to use and I can barely get my head around my bit of GL.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!