Loop Function Need In A Form !!! (help!)

Macaco

Active member
Joined
Jul 5, 2004
Messages
39
I have set up my opengl scene in a panel which is inside a form.
BUT I NEED A LOOP FUNCTION !!!!!

Theres no such thing as a message loop. I thought there might be some Idle callback (delegate, whatever) on my Form, so I can plug drawScene() to it, but there wasnt. I found one on the Application object (Application::add_Idle, but it doesnt function correctly), but even after I added an EventHandler to it, it didnt work (the GL view would update only if I moved the mouse really fast in the client area). Besides, Application::Idle is too "global" for my taste. Rigth now, Im doing it with timers: each 1 ms, I trigger a redraw. But this isnt efficient, and it locks me down to a fixed framerate. And what if the system is too slow? All those unprocessed WM_TIMER messages that would queue up... If anyone has a better idea, Id appreciate it.

thanks!!!! help !
 
Timers? Id just do

Dim GameOver as Boolean

Do While Not GameOver
Application.DoEvents
Do stuff
End While

and then somewhere else:
if e.keycode = keys.escape
{
GameOver = true;
}

<I tried my best to mix VB.NET / C++ / C# code :P. It seems as though youre using either C++ or C#, pretrty sure C++>

-The Pentium Guy
 
Yes, I know this loop, but the problem is WHERE do I put it????? Because Ive tried many places and It doesnt function correctly.
I mean....
do I have to put it inside onLoad function? (NO!!)
do I have to put it inside Application::Idle function? (NO!!!)
do I have to put it inside timer function? (NO!!!)

So where ??????

Thanks.
 
A seperate thread looks like a good idea.

If not on a separate thread at the end of your initialisation in an endles loop until you exit.
 
This is what i do:

Public Sub Load
DoTheLoop()
End Sub

Public Sub DoTheLoop()
Do While Not GameOver
Application.DoEvents
Do stuff
End While
End Sub


It realy doesnt matter where you call it, becuase when you do applicaiton.DoEvents, the program will also run other subs (ex: When you hit a key, it wont get "stuck" in the loop, itll go to the key event AND the loop at the same time.)

-The Pentium Guy
 
Macaco, are you trying to mean where should the object placed?

If you are, u can use PictureBox. I always use PictureBox for displaying the graphics.

An example would be like this:

While True
Dim a as Graphic = PictureBox1.CreateGraphics to make the picturebos drawable by new object.
Dim penLine as Pen(Color.Black,2)
g.DrawLine(penLine,100,100,200,200)
End While
 
- Ok Napivo, Ill find out about threads... (But I think there should be an easier way)

- Hi Pentium Guy,
the problem is that I must call it somewhere and depending on where I call it, it reacts different. If I use onLoad form function and I call i there (As I suppose you did), or I call it after all inicializations I cant see opengl window.
I have no problems about executing other subs while loop is running.
I mean.... I run the application, it inicialites the components and opengl window then once all is done I must call my loop funcion, but if I call it just after that (as onload) It doesnt function correctly, maybe the form inicialites other things after that.
So I should use another function which calls my loop after all all all.

- Hi George, I have already my object placed in a Panel and using timer function I can render the oepngl view clock after clock in the panel, but I dont want to use timer, i want to use another function call beacuse timer is slow and uneficient.

Thank you all !
 
Yeah, this option was a possible solution, in fact I saw it somewhere and I tried it but it didnt work either.

onLoad(){

//this->set_Visible(false);
this->ShowDialog();

while(this->Created) {
Show->Render();
Application::DoEvents();
}
}

but then there is an error message that says I must put form property visible to false, and when I do it the error message disapears, but the form is not showed, it does nothing. :(

Oh my god! Ive tried so many methods :(
 
Ok, I just have to find an eventHandler called when the form and its components are loaded and just showed...
Because for example If I made the loop when I click inside the panel (where the opengl scene is) the loop is called and works perfect. So I just have to call it when all is loaded and showed....

Ill keep on investigating...
 
Are you using Managed C++?
Tip: If you are, then use C#.

I really dont know much C++.NET, but Ive done this before in unmanaged.

Edit: It says you need to make your form visibilty property to false???? THats the most retarded thing Ive heard. Try creating a new project or something - .NET does go crazy at times (once, it refused to recognize the MessageBox.Show command).
 
Oh my god, at last!

Well, I solved it, its not a nice way but It works fine!!!!!!!!,

I just wanted to call the Loop function once all is loaded, so... because of I have a panel inside the form I call my loop function when the panel first paint handler calls its function:

with first_time boolean variable I will control that I will only be done once.


Void panel_x_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e)
{

if (first_time) {
first_time = false;
LoopFunction();
}
}


simple and effective.

A sincerely thank you to all of you guys! Ill post some images for you to see my project at the beggining of february. Thanks!!!


P.D. By the way, pentium guy, I do use c++ .net managed classes, and maybe it brought me more problems than I thought but for me its the most clean and structured way to program.
And the problem with MessageBox sometimes happens to me, you just have to "#undef MessageBox" at the top of the file and it will work.
 
Back
Top