Click here to Skip to main content
15,883,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I am trying learn something in OpenGL. I choose TAO framework for programming in C#. I just know how can I draw some shapes, change colors etc. but now I would like move with scene and I can't find out how. I am using component SimpleOpenGlControl from TAO Framework and I need redraw all scene after some event for example MoveMouse.

In constructor of Form I have all initial needs.
C#
double xrot = 0;

public Form1()
{
    InitializeComponent();

    int height = simpleOpenGlControl1.Height;
    int width = simpleOpenGlControl1.Width;

    simpleOpenGlControl1.InitializeContexts();
    Gl.glViewport(0, 0, width, height);

    Gl.glMatrixMode(Gl.GL_PROJECTION);
    Gl.glLoadIdentity();

    Glu.gluPerspective(45.0f, (double)width / (double)height, 0.01f, 5000.0f);

    Gl.glClearColor(1, 1, 1, 0);

    Gl.glMatrixMode(Gl.GL_MODELVIEW);
    Gl.glLoadIdentity();
}

Very simple drawing function.
C#
private void Draw()
{
    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); //clear buffers to preset values

    Gl.glMatrixMode(Gl.GL_MODELVIEW);
    Gl.glLoadIdentity();                 // load the identity matrix

    Gl.glTranslated(0, 0, -3);         
    Gl.glRotated(xrot++, 1, 0, 0); //rotate on x and increment

    Gl.glBegin(Gl.GL_TRIANGLES);
    Gl.glColor3d(1, 0, 0);
    Gl.glVertex2d(0, 0.5);
    Gl.glColor3d(0, 1, 0);
    Gl.glVertex2d(-0.5, -0.5);
    Gl.glColor3d(0, 0, 1);
    Gl.glVertex2d(+0.5, -0.5);
    Gl.glEnd();

    Gl.glFlush();
}

And calling function in Load and MouseMove events.
C#
private void simpleOpenGlControl1_Load(object sender, EventArgs e)
{
    Draw();
}
        
private void simpleOpenGlControl1_MouseMove(object sender, MouseEventArgs e)
{
    Draw();
}

Imidiatelly after start program is all right (scene is painted without move), but it doesn't do anything on MouseMove event - scene is still the same, without any move. I tryed any others events like KeyPress, MouseClick but still without succesfull. I tryed debug it as well but everything looks good. Can you tell me what's wrong?
Posted
Updated 23-Sep-13 0:30am
v4

1 solution

I got it! After calling Draw function I just add calling
C#
simpleOpenGlControl1.Draw();

and now it works very well! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900