0

So i want an OpenTK implementation, which does only draw a few images on a 2D window. I tried to go with what this answer provided, but it only drew a blue screen. I want to add that my understanding of OpenTK is basically not existant, I am just pissed by windows forms because it brings even simple graphical application to the brink of crashing. So far i got a GameWindow extension overriding OnLoad, OnResize, OnRenderFrame and OnUpdateFrame aswell as a perfectly sized NativeWindowSetting and GameWindowSetting.

Can someone please provide commented code (preferribly using OpenTK.Graphics.OpenGL4;)using or replacing the function:

public int LoadTexture(string file)
        {
            Bitmap bitmap = new Bitmap(file);

            int image;
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            GL.GenTextures(1, out image);
            GL.BindTexture(TextureTarget.Texture2D, image);

            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            bitmap.UnlockBits(data);


            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            return image;
        }

and code on how to put the resulting texture in the window?

I know usually SOF is used for asking question while providing code but i don't know where to start because all tutorials i found require triangles etc before doing the graphics but i do not need any geometry for my application.

Raphael-MdN
  • 123
  • 8
  • See [OpenTK examples](https://github.com/Rabbid76/c_sharp_opengl#opentk-examples) – Rabbid76 May 26 '21 at 15:02
  • "pissed by windows forms because it brings even simple graphical application to the brink of crashing". This does not match my experience. While it is not made for high performance use like games. It should work perfectly fine for simple tasks if used correctly. – JonasH May 26 '21 at 15:16
  • Thing is, the application has to draw about 10 pretty big (1920x1080) images, which would work okay enough but it has to resize them according to screen width and height (the original image is twice the default size) which slows down the performance insanely – Raphael-MdN May 26 '21 at 15:33
  • Also switching between display instances always looks like a gliched CS:GO graphic for about a second – Raphael-MdN May 26 '21 at 15:34
  • @Rabbid76 do you know how using OpenTK_library.OpenGL; is correctly added? OpenTK is installed correctly but VS can't seem to find said import. – Raphael-MdN May 26 '21 at 15:35
  • @Raphael-MdN This is a class library which is part of the GitHub repository. – Rabbid76 May 26 '21 at 15:37
  • 1
    Thanks, got it working now ^^ – Raphael-MdN May 26 '21 at 15:55

0 Answers0