Macaco Posted January 21, 2005 Posted January 21, 2005 I have set up my opengl scene in a panel which is inside a form. BUT I NEED A LOOP FUNCTION !!!!! There's 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 wasn't. I found one on the Application object (Application::add_Idle, but it doesn't function correctly), but even after I added an EventHandler to it, it didn't 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, I'm doing it with timers: each 1 ms, I trigger a redraw. But this isn't 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, I'd appreciate it. thanks!!!! help ! Quote
ThePentiumGuy Posted January 21, 2005 Posted January 21, 2005 Timers? I'd 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 you're using either C++ or C#, pretrty sure C++> -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Macaco Posted January 21, 2005 Author Posted January 21, 2005 Yes, I know this loop, but the problem is WHERE do I put it????? Because I've tried many places and It doesn't 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. Quote
Napivo1972 Posted January 21, 2005 Posted January 21, 2005 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. Quote
ThePentiumGuy Posted January 22, 2005 Posted January 22, 2005 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 doesn't 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 won't get "stuck" in the loop, it'll go to the key event AND the loop at the same time.) -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
georgepatotk Posted January 22, 2005 Posted January 22, 2005 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 Quote George C.K. Low
Macaco Posted January 22, 2005 Author Posted January 22, 2005 - Ok Napivo, I'll 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 can't 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 doesn't 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 don't want to use timer, i want to use another function call beacuse timer is slow and uneficient. Thank you all ! Quote
ThePentiumGuy Posted January 22, 2005 Posted January 22, 2005 Macaco: Call Me.Show before you call DoTheLoop. I had this same problem earlier. The thing is, the form1_Load event is called before the form is shown. -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Macaco Posted January 22, 2005 Author Posted January 22, 2005 Yeah, this option was a possible solution, in fact I saw it somewhere and I tried it but it didn't 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! I've tried so many methods :'( Quote
Macaco Posted January 22, 2005 Author Posted January 22, 2005 Ok, I just have to find an eventHandler called when the form and it's 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.... I'll keep on investigating... Quote
ThePentiumGuy Posted January 23, 2005 Posted January 23, 2005 Are you using Managed C++? Tip: If you are, then use C#. I really don't know much C++.NET, but I've done this before in unmanaged. Edit: It says you need to make your form visibilty property to false???? THat's the most retarded thing I've heard. Try creating a new project or something - .NET does go crazy at times (once, it refused to recognize the MessageBox.Show command). Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Macaco Posted January 23, 2005 Author Posted January 23, 2005 Oh my god, at last! Well, I solved it, it's 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! I'll 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 it's 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.