/SharpGL/Samples/WinForms/SharpGLTexturesSample/FormSharpGLTexturesSample.cs
# · C# · 116 lines · 75 code · 25 blank · 16 comment · 2 complexity · fce3a9e9b3ba30c16560cce3e1894c2c MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Text;
- using System.Windows.Forms;
-
- using SharpGL;
- using SharpGL.SceneGraph.Assets;
-
- namespace SharpGLTexturesSample
- {
- public partial class FormSharpGLTexturesSample : Form
- {
- public FormSharpGLTexturesSample()
- {
- InitializeComponent();
-
- // Get the OpenGL object, for quick access.
- SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
-
- // A bit of extra initialisation here, we have to enable textures.
- gl.Enable(OpenGL.GL_TEXTURE_2D);
-
- // Create our texture object from a file. This creates the texture for OpenGL.
- texture.Create(gl, "Crate.bmp");
- }
-
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- System.Diagnostics.Process.Start("http://nehe.gamedev.net");
- }
-
- private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
- {
- // Get the OpenGL object, for quick access.
- SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
-
- gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
- gl.LoadIdentity();
- gl.Translate(0.0f, 0.0f, -6.0f);
-
- gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);
-
- // Bind the texture.
- texture.Bind(gl);
-
- gl.Begin(OpenGL.GL_QUADS);
-
- // Front Face
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
-
- // Back Face
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
-
- // Top Face
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
-
- // Bottom Face
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
-
- // Right face
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
-
- // Left Face
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
- gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
- gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
- gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
- gl.End();
-
- gl.Flush();
-
- rtri += 1.0f;// 0.2f; // Increase The Rotation Variable For The Triangle
- }
-
-
- float rtri = 0;
-
- // The texture identifier.
- Texture texture = new Texture();
-
- private void buttonLoad_Click(object sender, EventArgs e)
- {
- // Show a file open dialog.
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- // Destroy the existing texture.
- texture.Destroy(openGLControl1.OpenGL);
-
- // Create a new texture.
- texture.Create(openGLControl1.OpenGL, openFileDialog1.FileName);
-
- // Redraw.
- openGLControl1.Invalidate();
- }
- }
- }
- }