C# OpenGL problem with animation
Posted
by
user3696303
on Programmers
See other posts from Programmers
or by user3696303
Published on 2014-06-03T08:27:39Z
Indexed on
2014/06/03
9:34 UTC
Read the original article
Hit count: 223
there is a program that simulates a small satellite and requires that a rotation animation of the satellite along the three axes. But when you try to write an animation problem during compilation: the program simply closes (shutdown occurs when swapbuffers, mainloop, redisplay), when you write the easiest programs have the same problem arose. Trying to catch exception by try-catch but here is not exception. How to solve this? I suffer with this a few days. Work in c# visual studio 2008 framework
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
try
{
InitializeComponent();
AnT1.InitializeContexts();
}
catch(Exception)
{
Glut.glutDisplayFunc(Draw);
Glut.glutTimerFunc(50, Timer, 0);
Glut.glutMainLoop();
}
}
void Timer(int Unused)
{
Glut.glutPostRedisplay();
Glut.glutTimerFunc(50, Timer, 0);
}
private void AnT1_Load(object sender, EventArgs e)
{
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
Gl.glClearColor(255, 255, 255, 1);
Gl.glViewport(0, 0, AnT1.Width, AnT1.Height);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(45, (float)AnT1.Width / (float)AnT1.Height, 0.1, 200);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glPushMatrix();
double xy = 0.2;
Gl.glTranslated(xy, 0, 0);
xy += 0.2;
Draw();
Glut.glutSwapBuffers();
Glut.glutPostRedisplay();
Gl.glPushMatrix();
Draw();
Gl.glPopMatrix();
}
void Draw()
{
Gl.glLoadIdentity();
Gl.glColor3f(0.502f, 0.502f, 0.502f);
Gl.glTranslated(-1, 0, -6);
Gl.glRotated(95, 1, 0, 0);
Glut.glutSolidCylinder(0.7, 2, 60, 60);
Gl.glLoadIdentity();
Gl.glColor3f(0, 0, 0);
Gl.glTranslated(-1, 0, -6);
Gl.glRotated(95, 1, 0, 0);
Glut.glutWireCylinder(0.7, 2, 20, 20);
}
}
}
© Programmers or respective owner