private void EnableTextures() { for (int i = 0; i < this.textures.Length; i++) { TextureBase itexture = this.textures[i]; if (itexture != null) { if (itexture.GetType() == typeof(Texture2D)) { Texture2D texture = (Texture2D)itexture; Gl.glActiveTexture(Gl.GL_TEXTURE0 + i); Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Handle); Gl.glEnable(Gl.GL_TEXTURE_2D); } if (itexture.GetType() == typeof(TextureCube)) { TextureCube cubetexture = (TextureCube)itexture; Gl.glActiveTexture(Gl.GL_TEXTURE0 + i); Gl.glBindTexture(Gl.GL_TEXTURE_CUBE_MAP, cubetexture.Handle); Gl.glEnable(Gl.GL_TEXTURE_CUBE_MAP); } } } }
public static TextureCube FromBitmap(Device device, Bitmap px, Bitmap py, Bitmap pz, Bitmap nx, Bitmap ny, Bitmap nz) { TextureCube texture = new TextureCube(); texture.device = device; texture.internalFormat = TextureFormat.RGB8; texture.type = ElementType.UByte; texture.baseformat = Gl.GL_BGR; texture.width = px.Width; px.RotateFlip(RotateFlipType.RotateNoneFlipY); nx.RotateFlip(RotateFlipType.RotateNoneFlipY); py.RotateFlip(RotateFlipType.RotateNoneFlipY); ny.RotateFlip(RotateFlipType.RotateNoneFlipY); pz.RotateFlip(RotateFlipType.RotateNoneFlipY); nz.RotateFlip(RotateFlipType.RotateNoneFlipY); Gl.glGenTextures(1, out texture.handle); Gl.glBindTexture(Gl.GL_TEXTURE_CUBE_MAP, texture.handle); Gl.glTexParameteri(Gl.GL_TEXTURE_CUBE_MAP, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST); Gl.glTexParameteri(Gl.GL_TEXTURE_CUBE_MAP, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST); Gl.glTexParameteri(Gl.GL_TEXTURE_CUBE_MAP, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE); Gl.glTexParameteri(Gl.GL_TEXTURE_CUBE_MAP, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE); BitmapData pxd = px.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, pxd.Scan0); px.UnlockBits(pxd); BitmapData nxd = nx.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, nxd.Scan0); nx.UnlockBits(nxd); BitmapData pyd = py.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, pyd.Scan0); py.UnlockBits(pyd); BitmapData nyd = ny.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, nyd.Scan0); ny.UnlockBits(nyd); BitmapData pzd = pz.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, pzd.Scan0); pz.UnlockBits(pzd); BitmapData nzd = nz.LockBits(new Rectangle(0, 0, texture.width, texture.width), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); Gl.glTexImage2D(Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, (int)texture.internalFormat, (int)texture.width, (int)texture.width, 0, (int)texture.baseformat, (int)texture.type, nzd.Scan0); nz.UnlockBits(nzd); Gl.glBindTexture(Gl.GL_TEXTURE_CUBE_MAP, 0); return(texture); }
/// <summary> /// Begins a FrameBuffer Pass. Binds a CubeTexture as the RenderTargets. /// </summary> /// <param name="buffer"></param> /// <param name="depthBuffer"></param> public void Begin(TextureCube colorTextureCube, TextureCubeFace face, ViewPort viewPort) { Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, this.handle); Gl.glFramebufferTexture2DEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT0_EXT, (int)face, colorTextureCube.Handle, 0); this.CheckStatus(Gl.glCheckFramebufferStatusEXT(Gl.GL_FRAMEBUFFER_EXT)); Gl.glPushAttrib(Gl.GL_VIEWPORT_BIT); this.device.ViewPort = viewPort; }
public static TextureCube FromFile(Device device, string px, string py, string pz, string nx, string ny, string nz) { Bitmap bpx = new Bitmap(px); Bitmap bnx = new Bitmap(nx); Bitmap bpy = new Bitmap(py); Bitmap bny = new Bitmap(ny); Bitmap bpz = new Bitmap(pz); Bitmap bnz = new Bitmap(nz); TextureCube textureCube = TextureCube.FromBitmap(device, bpx, bpy, bpz, bnx, bny, bnz); bpx.Dispose(); bnx.Dispose(); bpy.Dispose(); bny.Dispose(); bpz.Dispose(); bnz.Dispose(); return(textureCube); }
/// <summary> /// Begins a FrameBuffer Pass. Binds a CubeTexture and a DepthBuffer as the RenderTargets. Will automatically set the /// devices Viewport to match the dimensions of the Texture. /// </summary> /// <param name="buffer"></param> /// <param name="depthBuffer"></param> public void Begin(TextureCube colorTextureCube, DepthBuffer depthBuffer, TextureCubeFace face) { this.Begin(colorTextureCube, depthBuffer, face, new ViewPort(0, 0, colorTextureCube.Width, colorTextureCube.Width)); }