1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#region License
/*
MIT License
Copyright 2003-2005 Tao Framework Team
http://www.taoframework.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#endregion License
#region Original Credits / License
/*
texture.c
Nate Robins, 1997
A simple program to show how to do texture mapping.
*/
#endregion Original Credits / License
using System;
using Tao.FreeGlut;
using Tao.OpenGl;
namespace NateRobins {
#region Class Documentation
/// <summary>
/// A simple program to show how to do texture mapping.
/// </summary>
/// <remarks>
/// <para>
/// Original Author: Nate Robins
/// http://www.xmission.com/~nate/sgi.html
/// </para>
/// <para>
/// C# Implementation: Randy Ridge
/// http://www.taoframework.com
/// </para>
/// </remarks>
#endregion Class Documentation
public sealed class Texture {
// --- Fields ---
#region Private Fields
private static byte[] texture = {
0x80, 0x80, 0x80, 0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0xff, 0xff, 0xff, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0xff, 0xff, 0xff, 0x80, 0x80, 0x80,
};
#endregion Private Fields
// --- Entry Point ---
#region Run()
[STAThread]
public static void Run() {
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_SINGLE);
Glut.glutInitWindowSize(320, 320);
Glut.glutInitWindowPosition(50, 50);
Glut.glutCreateWindow("Texture");
Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
Glut.glutMainLoop();
}
#endregion Run()
// --- Callbacks ---
#region Display()
private static void Display() {
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glColor3ub(255, 255, 255);
Gl.glBegin(Gl.GL_TRIANGLES);
Gl.glNormal3f(0.0f, 0.0f, 1.0f);
Gl.glColor3ub(255, 0, 0);
Gl.glTexCoord2f(0.5f, 1.0f);
Gl.glVertex2f(0.0f, 2.0f);
Gl.glColor3ub(0, 255, 0);
Gl.glTexCoord2f(0.0f, 0.0f);
Gl.glVertex2f(-2.0f, -2.0f);
Gl.glColor3ub(0, 0, 255);
Gl.glTexCoord2f(1.0f, 0.0f);
Gl.glVertex2f(2.0f, -2.0f);
Gl.glEnd();
Gl.glFlush();
}
#endregion Display()
#region Keyboard(byte key, int x, int y)
private static void Keyboard(byte key, int x, int y) {
switch(key) {
case 27:
Environment.Exit(0);
break;
default:
break;
}
}
#endregion Keyboard(byte key, int x, int y)
#region Reshape(int width, int height)
private static void Reshape(int width, int height) {
Gl.glViewport(0, 0, width, height);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(60, 1.0, 0.1, 1000.0);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Glu.gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
Gl.glEnable(Gl.GL_COLOR_MATERIAL);
Gl.glEnable(Gl.GL_LIGHTING);
Gl.glEnable(Gl.GL_LIGHT0);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glPixelStorei(Gl.GL_UNPACK_ALIGNMENT, 1);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 3, 4, 4, 0, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, texture);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE);
}
#endregion Reshape(int width, int height)
}
}
|