Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: rotation, while resizing

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    17

    rotation, while resizing

    Hello all
    i am a beginner in OpenGL, i am using TAO framework with C#,
    i noticed that my render control stooped updating while re-sizing the window, i had overcome the problem of updating the content of the render control by calling the my game loop function in the event handler of the form re-size event

    but the rotation still have some work it is still not updated till the re-sizing process stop
    here is my code


    void GameLoop(double elapsedTime)
    {
    Gl.glViewport(0, 0, _openGLControl.Width, _openGLControl.Height);
    ////////////////////
    float r = Color.DarkBlue.R / 255.0f;
    float g = Color.DarkBlue.G / 255.0f;
    float b = Color.DarkBlue.B / 255.0f;
    float a = Color.DarkBlue.A / 255.0f;
    Gl.glClearColor(r, g, b, a);
    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
    Gl.glRotated(40 * elapsedTime, 0, 1, 0);
    Gl.glBegin(Gl.GL_TRIANGLES);
    {
    Gl.glColor3d(1, 1, 0);
    Gl.glVertex3d(-0.5,-0.5, 0);
    Gl.glColor3d(0, 1, 1);
    Gl.glVertex3d(0.5, -0.5, 0);
    Gl.glColor3d(1, 0, 1);
    Gl.glVertex3d(0, 0.5, 0);
    }
    Gl.glEnd();
    Gl.glFinish();
    _openGLControl.Refresh();
    }

    private void Form1_Resize(object sender, EventArgs e)
    {
    PreciseTimer _timer = new PreciseTimer();
    GameLoop(_timer.GetElapsedTime());
    }

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    17

    Re: rotation, while resizing

    hay, i thought that this is a place where i can find help from expertise

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    17

    Re: rotation, while resizing

    is there anyone who can help?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: rotation, while resizing

    it is still not updated till the re-sizing process stop
    That's because windows is event driven. When you are resizing the window an event is fired and the processing does not end until you stop the resizing with the mouse.
    So, if you want GL to carry on rendering and rotating objects, then you'll have to setup a separate thread and transfer all OpenGL rendering and main loop to that thread.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    17

    Re: rotation, while resizing

    i tried this

    namespace GameLoop
    {
    public partial class Form1 : Form
    {
    FastLoop _fastLoop;

    public Form1()
    {
    InitializeComponent();
    _openGLControl.InitializeContexts();
    backgroundWorker1.RunWorkerAsync();
    }

    void GameLoop(double elapsedTime)
    {
    Gl.glViewport(0, 0, _openGLControl.Width, _openGLControl.Height);
    ////////////////////
    float r = Color.DarkBlue.R / 255.0f;
    float g = Color.DarkBlue.G / 255.0f;
    float b = Color.DarkBlue.B / 255.0f;
    float a = Color.DarkBlue.A / 255.0f;
    Gl.glClearColor(r, g, b, a);
    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
    //Gl.glPointSize(25.0f);
    //Gl.glLineWidth(5.0f);
    Gl.glRotated(40 * elapsedTime, 0, 1, 0);
    Gl.glBegin(Gl.GL_TRIANGLES);
    {
    Gl.glColor3d(1, 1, 0);
    Gl.glVertex3d(-0.5,-0.5, 0);
    Gl.glColor3d(0, 1, 1);
    Gl.glVertex3d(0.5, -0.5, 0);
    Gl.glColor3d(1, 0, 1);
    Gl.glVertex3d(0, 0.5, 0);
    }
    Gl.glEnd();
    Gl.glFinish();
    if (this._openGLControl.InvokeRequired)
    {
    this._openGLControl.Invoke(new Action(Refresh));
    }
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    _fastLoop = new FastLoop(GameLoop);
    PreciseTimer _timer = new PreciseTimer();
    GameLoop(_timer.GetElapsedTime());
    }
    }
    }

    it didn't work, more over, it sometimes make run time errors "access to protected memory"

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: rotation, while resizing

    First of all, what were you trying to do with the code above?
    Separate threads? What you need to do is keep anything OpenGL related to the same single thread. That thread will create the GL context and render stuff to the window/context.
    No other thread can touch GL related data or context (keeping things simple). If you are getting memory access issues then it sounds like thread 1 is trying to access resources 'owned' by thread 2 or visa-versa.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •