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

  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.

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: rotation, while resizing

    I think the better question is why do you want your object rotating while the window is being resized?
    Resizing is something that the user does on a rare occasion so it should not be a problem for any type of app.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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