I am trying port a 2d game from GDI to OpenGL.
It is my understanding that in order to draw a picture on screen i need to draw a Quad and give a UV map and then apply the texture. With a bit of googling and thinking i made the quad and the UV. So now i want to draw a picture on said quad. The picture is a PNG with Transparenct. But the Alpha is kind of being ignored unless i specify something like “32bppArgb”.
The picture i am trying to draw:
and this is the output when i draw a 10x10 grid:
it seems like a channel problem since i have tried to shuffle around the byte order to match ARGB => BGRA || RGBA watnot.
I even tried something like like for test:
R = 255 G = 255 B = 255 A = A
This code should produce a white silhouette right? It’s red… Also this will yield excactly the same result:
R = 255 G = 0 B = 0 A = A
this setup is google and paste but not working.
var gl = openGLControl.OpenGL; var textureImage = Resources.Resource1.bg; gl.Enable(OpenGL.GL_TEXTURE_2D); gl.GenTextures(1, textures); gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures); gl.Enable(OpenGL.GL_BLEND); gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_DST_ALPHA); var locked = textureImage.LockBits( new Rectangle(0, 0, textureImage.Width, textureImage.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); gl.TexImage2D( OpenGL.GL_TEXTURE_2D, 0, 4, // found this number online, 4 channels = RGBA or something textureImage.Width, textureImage.Height, 0, OpenGL.GL_RGBA, // not sure what to put here OpenGL.GL_UNSIGNED_BYTE, locked.Scan0 ); // found this by google but not really sure what it does? gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
Any help is greatly appreciated. :sorrow: