luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenGL texture renders as solid color close to the average of the source image's pixels

TheRealNOIG opened this issue · comments

I know this is not the right place to get into contact with you but I couldn't find another way and Ive been banging my head agents this for a whole day now and I haven't been able to find someone who could help..

https://stackoverflow.com/questions/48675789/opengl-texture-renders-as-solid-color-close-to-the-average-of-the-source-images

Is there a way you've loaded in texture to projects of your own?

The first comment on questi9ne of Rabbit76 get the point.

Using shaders you do not need to enable textures (glEnable) , but requires to set the sampler uniform to the texture unit.

Gl.Uniform1i wants a ref but i have no idea what it wants to return to

GL.Uniform1i(int location, int count, ref T value);

Uae Gl.uniform1 (without i suffix),or pass a ref int (Int32 is a struct).

Nothing changed after adding Gl.Uniform1(shader.locationTextureSampler, 0);

Gl.ActiveTexture(TextureUnit.Texture0);
Gl.BindTexture(TextureTarget.Texture2d, texturedModel.texture.TextureID);
Gl.Uniform1(shader.locationTextureSampler, 0);

It seems like texture coordinates are all zeroes, mapping only the lower left pixel of the texture over triangles.

Can you see any changes if coloring the texture corners? If it is, then the problem is in texture coordinate passing.

Yes after painting all 4 corners black the texture change to black. it seems to be tacking the average of all 4 corners. Im going to switch from a cube to a quad to make things simpler

New model
public int[] indices = new int[] { 0,1,3, //Top left triangle (V0,V1,V3) 3,1,2 //Bottom right triangle (V3,V1,V2) };

public float[] textureCoords = { 0,0, //V0 0,1, //V1 1,1, //V2 1,0 //V3 };

public float[] vertexPositions = new float[] { -0.5f,0.5f,0, //V0 -0.5f,-0.5f,0, //V1 0.5f,-0.5f,0, //V2 0.5f,0.5f,0 //V3 };

Probably it take one on those, depending on how you lay the lines at load time (probably it is the upper left corner).

You should investigate on the texture coordinates, because the source of the issue is there.

This night I can check on stackoverflow.com, but now I have to leave, must gonna work.

Thank you so much for your help. I figured out the problem thanks to you. Also Thank you so much for making this amazing openGL wrapper. Its by far the best opengl wrapper for C#

https://i.gyazo.com/3c37e593c051203b7fc0001026798b77.mp4