protected override void DoInitialize() { base.DoInitialize(); this.lastTime = DateTime.Now; this.RotateSpeed = 0.2f; var bitmap = new Bitmap(@"sunColor.png"); var storage = new TexImage1D(0, GL.GL_RGBA, bitmap.Width, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bitmap)); var texture = new Texture(TextureTarget.Texture1D, storage, new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR) ); texture.Initialize(); bitmap.Dispose(); RenderUnit unit = this.RenderUnits[0]; ShaderProgram program = unit.Program; program.SetUniform("sunColor", texture); }
protected override void DoInitialize() { base.DoInitialize(); this.lastTime = DateTime.Now; this.RotateSpeed = 0.2f; string folder = System.Windows.Forms.Application.StartupPath; var bitmap = new Bitmap(System.IO.Path.Combine(folder, @"sunColor.png")); var storage = new TexImage1D(GL.GL_RGBA, bitmap.Width, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bitmap)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR) ); texture.Initialize(); bitmap.Dispose(); RenderMethod method = this.RenderUnit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("sunColor", texture); }
public static Texture Load() { //function to generate interpolated colours from the set of colour values (jet_values) //this function first calculates the amount of increments for each component and the //index difference. Then it linearly interpolates the adjacent values to get the //interpolated result. vec4[] pData = new vec4[256]; int[] indices = new int[9]; //fill the colour values at the place where the colour should be after interpolation for (int i = 0; i < 9; i++) { int index = i * 28; pData[index][0] = jet_values[i].x; pData[index][1] = jet_values[i].y; pData[index][2] = jet_values[i].z; pData[index][3] = jet_values[i].w; indices[i] = index; } //for each adjacent pair of colours, find the difference in the rgba values and then interpolate for (int j = 0; j < 9 - 1; j++) { float dDataR = (pData[indices[j + 1]][0] - pData[indices[j]][0]); float dDataG = (pData[indices[j + 1]][1] - pData[indices[j]][1]); float dDataB = (pData[indices[j + 1]][2] - pData[indices[j]][2]); float dDataA = (pData[indices[j + 1]][3] - pData[indices[j]][3]); int dIndex = indices[j + 1] - indices[j]; float dDataIncR = dDataR / (float)(dIndex); float dDataIncG = dDataG / (float)(dIndex); float dDataIncB = dDataB / (float)(dIndex); float dDataIncA = dDataA / (float)(dIndex); for (int i = indices[j] + 1; i < indices[j + 1]; i++) { pData[i][0] = (pData[i - 1][0] + dDataIncR); pData[i][1] = (pData[i - 1][1] + dDataIncG); pData[i][2] = (pData[i - 1][2] + dDataIncB); pData[i][3] = (pData[i - 1][3] + dDataIncA); } } var storage = new TexImage1D(GL.GL_RGBA, 256, GL.GL_RGBA, GL.GL_FLOAT, new ArrayDataProvider <vec4>(pData)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); return(texture); }
private void GetTextures(out Texture texture0, out Texture texture1, out Texture texture2) { { string folder = System.Windows.Forms.Application.StartupPath; var bmp = new Bitmap(System.IO.Path.Combine(folder, @"base.png")); TexStorageBase storage = new TexImageBitmap(bmp); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); bmp.Dispose(); texture0 = texture; } { string folder = System.Windows.Forms.Application.StartupPath; var bmp = new Bitmap(System.IO.Path.Combine(folder, "Rainbow.png")); TexStorageBase storage = new TexImage1D(GL.GL_RGBA, bmp.Width, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); bmp.Dispose(); texture1 = texture; } { string folder = System.Windows.Forms.Application.StartupPath; var bmp = new Bitmap(System.IO.Path.Combine(folder, @"fish.png")); bmp.RotateFlip(RotateFlipType.Rotate180FlipX); TexStorageBase storage = new TexImageBitmap(bmp); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); bmp.Dispose(); texture2 = texture; } }
private Texture GetTexture() { string folder = System.Windows.Forms.Application.StartupPath; var bmp = new Bitmap(System.IO.Path.Combine(folder, "Rainbow.png")); TexStorageBase storage = new TexImage1D(GL.GL_RGBA, bmp.Width, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); bmp.Dispose(); return(texture); }
private Texture InitTFF1DTexture(string filename) { var bitmap = new System.Drawing.Bitmap(filename); const int width = 256; var storage = new TexImage1D(GL.GL_RGBA8, width, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bitmap)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_NEAREST), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_NEAREST)); texture.Initialize(); texture.TextureUnitIndex = 0; bitmap.Dispose(); return(texture); }
private Texture InitTFF1DTexture(string filename) { byte[] tff; using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) using (var br = new BinaryReader(fs)) { tff = br.ReadBytes((int)fs.Length); } const int width = 256; var storage = new TexImage1D(GL.GL_RGBA8, width, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, new ArrayDataProvider <byte>(tff)); var texture = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_NEAREST), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_NEAREST)); texture.Initialize(); return(texture); }