PDA

View Full Version : rotation, while resizing



AhmedSabry
01-29-2012, 02:50 PM
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());
}

AhmedSabry
01-31-2012, 01:56 PM
hay, i thought that this is a place where i can find help from expertise

AhmedSabry
01-31-2012, 01:56 PM
is there anyone who can help?

BionicBytes
02-02-2012, 02:26 AM
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.

AhmedSabry
02-02-2012, 03:52 PM
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"

BionicBytes
02-03-2012, 08:55 AM
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.

V-man
02-04-2012, 07:31 AM
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.