Converting to borland code, but.....
Hi there GL Fans!
Ok, just a few weeks ago, I started to study OpenGL a bit, with the help of NeHe''s tutors (and the Delphi conversion bij Marc Aarts, tutor no.1), using Borland Delphi 6. I''m quite much grown into the standard delphi way of working (the borland way of making forms, adding buttons, setting the properties of those things etc). Marc Aart''s conversion, however, uses what I''d call the microsoft way of coding. Can''t remember the name of the damn thing, but working with the hwnd class to set up a window etc, you know. So I thought : I want to learn OpenGL, so why not right away convert that first tutor to use borland code? That way, I''ll learn something more about GL and probably some more about Delphi right away, and I can do it my way.
By now, I''ve done most of the conversion already. But there''s just one thing I don''t understand, and that I can''t find any documentation for right now. An instance of the whnd class is being made, and some properties are set. Then there comes this scentence in the code :
h_Dc := GetDC(h_Wnd);
Now, I''m not entirely sure what''s being done here. The device-context is being linked somehow to our hwnd class. Am I right that the device-context is about the same as a viewport? And that this viewport takes the size of it''s parent, which in this case is the instance of hwnd (the form or window, so to say)? Or am I thinking something wrong here? I''m asking, because in borland, when I link an instance of the TForm class (MainForm) to it like this :
h_Dc := GetDC(MainForm);
I''m getting the error "Incompatible types : ''HWND'' and ''TMainForm'';
Can anyone give me the correct code and an explanation of what this device-context is and what happens here? NeHe''s not very clear either, he only tells that a device-context is needed to draw to a window.
Thanks a lot!
Ok - ummm, I''m not sure how much you undertstand about the Win32 GDI so I''m going to take you through this assuming you know nothing.
As you know, a HWND is a windows handle to a window - the reason for this is that windows needs a way to keep track of the windows. There are several properties that windows internally associates with a window handle, in order to display all the windows correctly. Windows in Windows (*g* This could get confuzzling!) have a z-order, a title, an icon, a menu and other things. The thing we''re interested in is a HDC.
A HDC is a windows handle to a device context, which is I suppose you could assume is the equivalent to an offscreen surface. It is an image, however in order to make things easy for the programmers, windows (handily enough) gives us an abstract way of handling drawing surfaces. There''s a whole plethora of Win32 GDI functions, functions for drawing circles, lines, filling regions etc etc... And one of these surfaces is associated with our window. Great stuff! The only drawback is that the Win32 GDI is slow as hell because microsoft didn''t think (duh) that game programmers really wanted hardware acceleration (well we can only assume...) and therefore DirectX came out and (of course) OpenGL is better, but microsoft paid big companies to develop using DirectX and yada yada yada...
Anyway - I hope this somewhat answers your question
As you know, a HWND is a windows handle to a window - the reason for this is that windows needs a way to keep track of the windows. There are several properties that windows internally associates with a window handle, in order to display all the windows correctly. Windows in Windows (*g* This could get confuzzling!) have a z-order, a title, an icon, a menu and other things. The thing we''re interested in is a HDC.
A HDC is a windows handle to a device context, which is I suppose you could assume is the equivalent to an offscreen surface. It is an image, however in order to make things easy for the programmers, windows (handily enough) gives us an abstract way of handling drawing surfaces. There''s a whole plethora of Win32 GDI functions, functions for drawing circles, lines, filling regions etc etc... And one of these surfaces is associated with our window. Great stuff! The only drawback is that the Win32 GDI is slow as hell because microsoft didn''t think (duh) that game programmers really wanted hardware acceleration (well we can only assume...) and therefore DirectX came out and (of course) OpenGL is better, but microsoft paid big companies to develop using DirectX and yada yada yada...
Anyway - I hope this somewhat answers your question
Thank you very very much for the solution and this explanation guys! I haven''t got time to try it right away, but when I do, I''ll tell ya how it goes! This''ll be a lot of help I guess.
I''m not sure exactly if I should still write this, but to get the HWND of MainForm you''d use MainForm.Handle???
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement