private void openGLControl1_OpenGLInitialized(object sender, EventArgs e) { // Get the OpenGL object, for quick access. SharpGL.OpenGL gl = this.openGLControl1.OpenGL; // We need to load the texture from file. textureImage = new Bitmap("Crate.bmp"); // A bit of extra initialisation here, we have to enable textures. gl.Enable(OpenGL.GL_TEXTURE_2D); // Get one texture id, and stick it into the textures array. gl.GenTextures(1, textures); // Bind the texture. gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]); // Tell OpenGL where the texture data is. gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0); // Specify linear filtering. gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); }
public FormExample2() { InitializeComponent(); // Get the OpenGL object, for quick access. SharpGL.OpenGL gl = this.openGLControl1.OpenGL; // We need to load the texture from file. textureImage = new Bitmap("Crate.bmp"); // A bit of extra initialisation here, we have to enable textures. gl.Enable(OpenGL.TEXTURE_2D); // Get one texture id, and stick it into the textures array. gl.GenTextures(1, textures); // Bind the texture. gl.BindTexture(OpenGL.TEXTURE_2D, textures[0]); // Tell OpenGL where the texture data is. gl.TexImage2D(OpenGL.TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.RGB, OpenGL.UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0); gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MIN_FILTER, OpenGL.LINEAR); // Linear Filtering gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MAG_FILTER, OpenGL.LINEAR); // Linear Filtering }
/// <summary> /// This function creates the underlying OpenGL object. /// </summary> /// <param name="gl"></param> /// <returns></returns> public virtual bool Create(OpenGL gl) { // If the texture currently exists in OpenGL, destroy it. Destroy(gl); // Generate and store a texture identifier. gl.GenTextures(1, glTextureArray); return(true); }
/// <summary> /// This function creates the underlying OpenGL object. /// </summary> /// <param name="gl"></param> /// <returns></returns> public virtual bool Create(OpenGL gl) { // If the texture currently exists in OpenGL, destroy it. Destroy(gl); // Generate and store a texture identifier. gl.GenTextures(1, glTextureArray); return true; }
private void openGLControl1_OpenGLInitialized(object sender, EventArgs e) { SharpGL.OpenGL gl = this.openGLControl1.OpenGL; textureImage = new Bitmap("MyPicture/Texture.bmp"); gl.Enable(OpenGL.GL_TEXTURE_2D); gl.GenTextures(1, textures); gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]); gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb).Scan0); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); }
private void openGLControl1_OpenGLInitialized(object sender, EventArgs e) { SharpGL.OpenGL gl = this.openGLControl1.OpenGL; gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl.ClearDepth(1.0f); // Setup lightning gl.Enable(OpenGL.GL_LIGHTING); gl.Enable(OpenGL.GL_LIGHT0); gl.Enable(OpenGL.GL_LIGHT1); gl.Enable(OpenGL.GL_COLOR_MATERIAL); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, new float[] { 0.8f, 0.8f, 0.8f }); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, new float[] { 1f, 1f, 1f }); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, lightPos0); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_CUTOFF, 45); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_EXPONENT, 15); gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_DIRECTION, new float[] { 1f, 1f, 1f }); gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE, new float[] { 1, 1, 1, 1 }); gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT, new float[] { 1, 1, 1, 1 }); textureImage = new Bitmap("texture.bmp"); gl.Enable(OpenGL.GL_TEXTURE_2D); // Get one texture id, and stick it into the textures array. gl.GenTextures(1, textures); gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]); // Set texture data. gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0); // Specify linear filtering. gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); }
public Texture(OpenGL gl) { _gl = gl; _gl.GenTextures(1, _texture); }
private void InitializeTexture(ref OpenGL gl) { gImage1 = new Bitmap(@"C:\Users\Lee\Documents\GitHub\SmackBrosClient\SmackBrosClient\files\meleemenu1.jpg"); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, gImage1.Width, gImage1.Height); gbitmapdata = gImage1.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); gImage1.UnlockBits(gbitmapdata); gl.GenTextures(1, gtexture); gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]); gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, gImage1.Width, gImage1.Height, 0, OpenGL.GL_BGR_EXT, OpenGL.GL_UNSIGNED_BYTE, gbitmapdata.Scan0); gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); TexturesInitialised = true; }
public void InitTexture(OpenGL renderer) { if (String.IsNullOrEmpty(Texture)) { return; } // We need to load the texture from file. var textureImage = new Bitmap(Texture); renderer.Enable(OpenGL.GL_TEXTURE_2D); // Get one texture id, and stick it into the textures array. renderer.GenTextures(1, _textures); // Bind the texture. renderer.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[0]); // Tell OpenGL where the texture data is. renderer.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0); // Specify linear filtering. renderer.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); }