m workin on visual c#2008 and using Tao.openGl for drawing some graphics. my code draws the cube but doesnt recognize any keyboard/mouse interrupts…
please help me out
// form1.cs code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tao.Platform.Windows;
using Tao.OpenGl;
using Tao.FreeGlut;
namespace tao2cube
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB|Glut.GLUT_DEPTH);
Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);//for Background
Gl.glColor3f(1.0f, 1.0f, 0.0f);//colour for the primitive
Gl.glPointSize(5.0f);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glOrtho(-1.0, 1.0, -1.0, 1.0,-1.0,1.0);
this.simpleOpenGlControl1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.simpleOpenGlControl1_KeyPress);
Gl.glEnable(Gl.GL_DEPTH_TEST);
}
private void simpleOpenGlControl1_Resize(object sender, EventArgs e)
{
Size s = new Size();
this.OnResize(e);
reshape(s.Width, s.Height);
Glut.glutPostOverlayRedisplay();
}
private void simpleOpenGlControl1_KeyPress(object sender, KeyPressEventArgs e)
{
this.OnKeyPress(e);
Point p = new Point();
p = MousePosition;
Keys key = new Keys();
int k = System.Convert.ToInt32(key);
specialKey(k,p.X,p.Y);
}
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
this.OnPaint(e);
drawings();
Glut.glutPostOverlayRedisplay();
// Glut.glutSwapBuffers();
}
private void simpleOpenGlControl1_Load(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
static float[] theta={0,0,0};
static int axis=2;
public static void drawings()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT );
Gl.glPushMatrix();
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glVertex3f(0.25f, 0.25f, 1.0f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(-0.75f, 0.25f, 1f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(-0.75f, -0.75f, 1f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(0.25f, -0.75f, 1f);
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glVertex3f(0.5f, 0.5f, 0f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(-0.5f, 0.5f, 0f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(-0.5f, -0.5f, 0f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(0.5f, -0.5f, 0f);
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(-0.5f, 0.5f, 0f);
Gl.glColor3f(1f, 0.5f, 1f);
Gl.glVertex3f(-0.75f, 0.25f, 1f);
Gl.glColor3f(0.6f, 0.5f, 1.0f);
Gl.glVertex3f(-0.75f, -0.75f, 1f);
Gl.glColor3f(1f, 0f, 0.5f);
Gl.glVertex3f(-0.5f, -0.5f, 0f);
Gl.glColor3f(0f, 0.5f, 1.0f);
Gl.glVertex3f(0.5f, -0.5f, 0f);
Gl.glColor3f(0f, 0.5f, 0f);
Gl.glVertex3f(0.25f, -0.75f, 1f);
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glVertex3f(0.5f, 0.5f, 0f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glVertex3f(0.25f, 0.25f, 1f);
Gl.glColor3f(1f, 0.5f, 0f);
Gl.glEnd();
Gl.glFlush();
Gl.glPopMatrix();
Glut.glutPostOverlayRedisplay();
}
public static void spincube()
{
theta[axis] += 0.2f;
if (theta[axis] > 360) theta[axis] -= 360;
Glut.glutPostRedisplay();
}
public static void specialKey(int key,int x,int y)
{
// Check which key is pressed
switch (key)
{
case Glut.GLUT_KEY_LEFT: // Rotate on x axis
axis = 0;
break;
case Glut.GLUT_KEY_RIGHT: // Rotate on x axis (opposite)
axis = 1;
break;
case Glut.GLUT_KEY_UP: // Rotate on y axis
axis = 2;
break;
default:
break;
}
spincube();
Glut.glutPostOverlayRedisplay();
}
public static void reshape(int w, int h)
{
Gl.glViewport(0, 0, w, h);
Gl.glMatrixMode(Gl.GL_PROJECTION); // Set the Matrix mode
Gl.glLoadIdentity();
if (w <= h)
{
Gl.glOrtho(-2, 2, -2 * (float)h / (float)w, 2 * (float)h / (float)w, -10, 10); ;
}
else
{
Gl.glOrtho(-2, 2, -2 * (float)h / (float)w, 2 * (float)h / (float)w, -10, 10);
}
Gl.glMatrixMode(Gl.GL_MODELVIEW);
}
}
}
// form1.cs code over
// program.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Tao.FreeGlut;
using Tao.OpenGl;
using Tao.Platform.Windows;
namespace tao2cube
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB);
Glut.glutReshapeFunc(tao2cube.Form1.reshape);
Glut.glutDisplayFunc(tao2cube.Form1.drawings);
Glut.glutIdleFunc(tao2cube.Form1.drawings);
Glut.glutSpecialFunc(new Glut.SpecialCallback(tao2cube.Form1.specialKey));
Application.Run(new Form1());
Glut.glutMainLoop();
}
}
}