在事件上重绘场景 [英] Redrawing scene on a event

查看:89
本文介绍了在事件上重绘场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试在OpenGL中学习一些东西。我选择TAO框架在C#中编程。我只知道如何绘制一些形状,改变颜色等,但现在我想移动场景,我不知道如何。我正在使用来自TAO Framework的组件SimpleOpenGlControl,我需要在一些事件之后重绘所有场景,例如MoveMouse。



在Form I的构造函数中有所有初始需求。

  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();
}



非常简单的绘图功能。

  private   void  Draw()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); // 清除预设值的缓冲区

Gl.glMatrixMode(Gl.GL_MODELVIEW );
Gl.glLoadIdentity(); // 加载单位矩阵

Gl.glTranslated( 0 0 , - 3);
Gl.glRotated(xrot ++, 1 0 0 ); // 旋转x和增量

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();
}



在Load和MouseMove事件中调用函数。

  private   void  simpleOpenGlControl1_Load( object  sender,EventArgs e)
{
Draw();
}

private void simpleOpenGlControl1_MouseMove( object sender,MouseEventArgs e)
{
Draw();
}



启动程序后的Imidiatelly可以(场景没有移动),但它在MouseMove事件上没有做任何事情 - 场景仍然是同样,没有任何动作。我尝试了其他任何事件,如KeyPress,MouseClick,但仍然没有成功。我尝试调试它,但一切看起来都不错。你能告诉我什么是错的吗?

解决方案

我明白了!调用Draw函数后,我只需添加调用

 simpleOpenGlControl1.Draw(); 



现在它非常有用好! :)


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.

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.

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.

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?

解决方案

I got it! After calling Draw function I just add calling

simpleOpenGlControl1.Draw();


and now it works very well! :)


这篇关于在事件上重绘场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆