Update of /cvsroot/csdopenglnet/tutorials/lesson03
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26810/lesson03
Added Files:
Makefile lesson03.cs
Log Message:
new lessons
--- NEW FILE: Makefile ---
CC=mcs
DEBUG=/d:DEBUG
DEBUG=
OPTS=$(DEBUG)
LIBS=csdGL.dll
MCS=$(CC) $(OPTS) -lib:/usr/lib/mono/csDragons -lib:/usr/lib/mono/gtk-sharp
FILES = lesson03.exe
all: $(FILES)
%.exe:%.cs
$(MCS) -r:csdGL.dll $^ -o $@
clean:
rm -f $(FILES)
.IGNORE:
clean
.EXPORT_ALL_VARIABLES:
.PHONY:
clean
--- NEW FILE: lesson03.cs ---
using csDragons.OpenGL;
using System;
public class Lesson03 : csdGL {
public Lesson03() {
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( 640, 480 );
glutCreateWindow("Lesson 03");
initGL();
glutDisplayFunc( new cb0_glutDisplayFunc( draw ) );
glutKeyboardFunc( new cb0_glutKeyboardFunc(keyboard) );
glutReshapeFunc( new cb0_glutReshapeFunc( reshape ) );
glutVisibilityFunc( new cb0_glutVisibilityFunc( visibility ) );
glutMainLoop();
}
protected void visibility( int status ) {
if ( status == GLUT_VISIBLE ) {
draw();
} else {
glutIdleFunc( null );
}
}
protected void initGL() {
glShadeModel( GL_SMOOTH );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
}
protected void reshape2( int width, int height ) {
float h = ((float)height) / ((float)width);
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -h, h, 5.0, 5.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
// glTranslatef (0.0f, 0.0f, -40.0f);
}
protected void reshape( int width, int height ) {
if (height==0) height = 1;
float h = ((float)width) / ((float)height);
glViewport (0, 0, width, height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, h, 0.1f, 150.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
protected void draw() {
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glColor3f( 1.0f, 0.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f( 0.0f, 0.0f, 1.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef( 3.0f, 0.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
protected void keyboard( byte key, int x, int y ) {
if (key==27) System.Environment.Exit(0);
}
public static void Main( string[] args) {
new Lesson03();
}
}
|