giawa / opengl4csharp

OpenGL 4 Bindings (partially based on OpenTK) for C#
Other
232 stars 61 forks source link

How to deal with 1D Textures? #9

Closed tomb18 closed 7 years ago

tomb18 commented 7 years ago

Hi, I'm having great success with your c# libraries. I am stuck on something though. I have a heightmap where I need the heights colored according to a gradient I created. This is

        //here is the texture 
        myTextureData[0].X = 0x00;      //blue
        myTextureData[0].Y = 0x00;
        myTextureData[0].Z = 0xFF;
        myTextureData[0].W = 0xFF;

        myTextureData[0].X = 0xFF;      //yellow
        myTextureData[0].Y = 0xFF;
        myTextureData[0].Z = 0x00;
        myTextureData[0].W = 0xFF;

        myTextureData[0].X = 0xFF;      //red
        myTextureData[0].Y = 0x00;
        myTextureData[0].Z = 0x00;
        myTextureData[0].W = 0xFF;

I want to feed this to a fragment shader so that colors are assigned to my vertices. COuld you please give a hint as to how I would accomplish this? I understand I do not need texture coordinates defined for this. Thanks a bunch!

tomb18 commented 7 years ago

Hi, I realize that the above is incorrect. What I am trying to do is create a 1D texture. So I have this: Texel[] mytexturedata = { new Texel() { r = 0x00, g = 0xFF, b = 0x00, a = 0xFF }, // Green new Texel() { r = 0xFF, g = 0xFF, b = 0x00, a = 0xFF }, // Yellow new Texel() { r = 0xFF, g = 0x00, b = 0x00, a = 0xFF } // Red }; I now need to do all of the opengl bindings. However in your tutorial you only show creating a texture based on a bitmap. This will not work here. So I have tried the following:

        var test = Gl.GenTexture();
        Gl.BindTexture(TextureTarget.Texture1DArray, test);

But my guess is that that is nowhere close to what I need to do. Could you please help out here? Thanks

tomb18 commented 7 years ago

I have a complete example on StackOverflow. Here is the link: http://stackoverflow.com/questions/41644191/coloring-a-heightmap-with-1d-texture-in-c-sharp-and-opengl Please help!! You are the only person out there that knows your libraries and gives us examples in C#.

giawa commented 7 years ago

Hey tomb18,

Sorry for the delay in getting back to you. This got completely lost in my e-mail. Did you end up having any luck with this? You should be able to load a 1 dimensional texture into OpenGL no problem using the normal Texture class. You can then just address the texture using normal UV mapping (using only either the U or the V). You could base the U or V off the height data that comes from your vertex shader (I'm assuming this would be the y component).

If you truly want to use a 1 dimensional texture target then you will have to avoid the Texture class and do what you have suggested (Texture1D).

Cheers

giawa commented 7 years ago

Hey tomb18,

Please re-open this issue if you're still having issues. I'm going to close it for now.

tomb18 commented 7 years ago

Hi I ended up using a 2D texture just as easy. BTW, using your tutorials and libraries and a lot of trial and error I wrote this:

https://www.youtube.com/watch?v=AwB-4OycS6o

It uses only 1 open GL call every time it plots the heightMap. The data comes from a fast fourier transform of 2048 points 10 times a second.

I wish I knew C++, I’ve only used C#. It makes it tough to find examples that make sense but your libraries helped me through it.

thanks, Tom

From: giawa Sent: Thursday, March 16, 2017 7:01 PM To: giawa/opengl4csharp Cc: tomb18 ; Author Subject: Re: [giawa/opengl4csharp] How to deal with 1D Textures? (#9)

Hey tomb18,

Sorry for the delay in getting back to you. This got completely lost in my e-mail. Did you end up having any luck with this? You should be able to load a 1 dimensional texture into OpenGL no problem using the normal Texture class. You can then just address the texture using normal UV mapping (using only either the U or the V). You could base the U or V off the height data that comes from your vertex shader (I'm assuming this would be the y component).

If you truly want to use a 1 dimensional texture target then you will have to avoid the Texture class and do what you have suggested (Texture1D).

Cheers

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.


This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

giawa commented 7 years ago

Hey tomb18,

That looks awesome! I use the fourier transform all of the time at work, so this is really neat to see! I'm glad you were able to get it working, and sorry I wasn't able to help much when you were actively working on it. Please feel free to open any new issues if you run into bugs/issues or want to ask a question.

Take care