Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Do Mai 23, 2024 05:50

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 28 Beiträge ]  Gehe zu Seite Vorherige  1, 2
Autor Nachricht
 Betreff des Beitrags:
BeitragVerfasst: Di Mär 27, 2007 19:13 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
Try it using a power of two texture.
Maybe GL_TEXTURE_RECTANGLE_ARB is not supported or check for errors using glGetError

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Cripes.
BeitragVerfasst: Di Mär 27, 2007 19:19 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
I just tried this .exe on my girlfriend's laptop - a brand new Samsung Q35 - and it got an error from TglBitmap2D when pressing the second button - the error was about non-power of two textures. Seems it has different behaviour on different systems.

I also tried it on a ThinkPad T40 - that works the same as my development machine - blank, black screen when pressing the "Start OpenGL" button - but no error.

So... my question becomes - is it something at fault with my setup, or levels of some things - or a problem with my code, or a problem with the utility code I'm using? Much more likely something to do with me or my stuff.

Is there another way to convert a TBitmap to a Texture? I saw something on NeHE I thought - lesson 38, but it looked quite complicated.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: OK...
BeitragVerfasst: Di Mär 27, 2007 19:19 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
I'll do that!

And report back.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Possible hint?
BeitragVerfasst: Di Mär 27, 2007 19:43 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
Right... I altered the ClientWidth and ClientHeight of the TForm to be 512.

I get the same on my development system and on the ThinkPad T40. On the Samsung Q35 I no longer get an error message, and am presented with a white box on the screen. There is no representation of the GDI stuff though.

However, I posted it to a friend and asked him what he saw, he replied: "I see a smaller snapshot of the program." so, there you go... and that's on a proper PC. He is going to try it on a ThinkPad T43 later and let me know what it does.

I'm starting to suspect that it won't work on laptops.

When I run through my card's capabilities, I get the following returned... because I don't see something exactly like GL_TEXTURE_RECTANGLE_ARB, the closest is GL_EXT_texture_rectangle, does that mean this will never work? I assume I should be looking for something like GL_ARB_texture_rectangle reported?

GL_ARB_multitexture; GL_EXT_texture_env_add; GL_EXT_compiled_vertex_array; GL_S3_s3tc; GL_ARB_occlusion_query; GL_ARB_point_parameters; GL_ARB_texture_border_clamp; GL_ARB_texture_compression; GL_ARB_texture_cube_map; GL_ARB_texture_env_add; GL_ARB_texture_env_combine; GL_ARB_texture_env_crossbar; GL_ARB_texture_env_dot3; GL_ARB_texture_mirrored_repeat; GL_ARB_transpose_matrix; GL_ARB_vertex_blend; GL_ARB_vertex_buffer_object; GL_ARB_vertex_program; GL_ARB_window_pos; GL_ATI_element_array; GL_ATI_envmap_bumpmap; GL_ATI_fragment_shader; GL_ATI_map_object_buffer; GL_ATI_texture_env_combine3; GL_ATI_texture_mirror_once; GL_ATI_vertex_array_object; GL_ATI_vertex_attrib_array_object; GL_ATI_vertex_streams; GL_ATIX_texture_env_combine3; GL_ATIX_texture_env_route; GL_ATIX_vertex_shader_output_point_size; GL_EXT_abgr; GL_EXT_bgra; GL_EXT_blend_color; GL_EXT_blend_func_separate; GL_EXT_blend_minmax; GL_EXT_blend_subtract; GL_EXT_clip_volume_hint; GL_EXT_draw_range_elements; GL_EXT_fog_coord; GL_EXT_multi_draw_arrays; GL_EXT_packed_pixels; GL_EXT_point_parameters; GL_EXT_rescale_normal; GL_EXT_secondary_color; GL_EXT_separate_specular_color; GL_EXT_stencil_wrap; GL_EXT_texgen_reflection; GL_EXT_texture3D; GL_EXT_texture_compression_s3tc; GL_EXT_texture_cube_map; GL_EXT_texture_edge_clamp; GL_EXT_texture_env_combine; GL_EXT_texture_env_dot3; GL_EXT_texture_filter_anisotropic; GL_EXT_texture_lod_bias; GL_EXT_texture_mirror_clamp; GL_EXT_texture_object; GL_EXT_texture_rectangle; GL_EXT_vertex_array; GL_EXT_vertex_shader; GL_HP_occlusion_test; GL_NV_blend_square; GL_NV_occlusion_query; GL_NV_texgen_reflection; GL_SGI_color_matrix; GL_SGIS_generate_mipmap; GL_SGIS_multitexture; GL_SGIS_texture_border_clamp; GL_SGIS_texture_edge_clamp; GL_SGIS_texture_lod; GL_SUN_multi_draw_arrays; GL_WIN_swap_hint; WGL_EXT_extensions_string; WGL_EXT_swap_control

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: More info...
BeitragVerfasst: Di Mär 27, 2007 20:05 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
OK, putting:

Code:
  1. ShowMessage (gluErrorString (glGetError));
...in my Draw procedure shows that I'm getting a STACK OVERFLOW... 1283, $503.

Is this because the capability is not supported or something else to do with the Push and PopMatrix? If I remove these, then the error does go away, but I still don't get anything except the black, blank screen after pressing "Start OpenGL".

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Stuffed?
BeitragVerfasst: Di Mär 27, 2007 20:08 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
However, it also works on my friend's laptop... a ThinkPad T43 with a Radeon Mobility X300.

If it is to do with GL_TEXTURE_RECTANGLE_ARB, is there another means of achieving what I want to do here?

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Confirmation.
BeitragVerfasst: Di Mär 27, 2007 20:16 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
Sorry about these quickfire responses... I've been trying lots of systems... it also works as you would expect on my HTPC.

I didn't really expect to have to cater for different setups when using OpenGL I must admit. I didn't think that anything I was doing would actually stretch video cards beyond their capabilities. The systems I have been trying are not that old.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Thank-you!
BeitragVerfasst: Di Mär 27, 2007 22:11 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
I think that I've now got a good handle on why this works and doesn't work on different systems.

I'd like to thank both i0n0s and Lossy eX for trying to assist me in this. If there are any views on a better (or less restrictive in terms of hardware requirements) way of doing this, I would be most interested in hearing them. Any method of converting a TBitmap to a Texture would be of real interest to me.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Mär 27, 2007 22:16 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
At that point I would suggest you another solution:
That GDI mixed with OpenGL is a workaround. So just rethink if you're realy need GDI or better what you need from GDI:
At the moment we're working on an DGLGUI, the work has slow process, but at that point we have same basics. If you're just require some buttons you can use this or the GUI from X-Dream.
This will be a better solution than working that long on a problem that should be only temporary.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Close...
BeitragVerfasst: Di Mär 27, 2007 23:17 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
I understand. However, the real issue here is all the GDI code that I have already written.

I can't really abandon it for pure OpenGL just like that I'm afraid - "temporary solution" might mean months in the case of my project. I will get there though. For now, to proceed down the OpenGL path, I really want to find out how to fix this. I am surprised it is proving so challenging to simply display a TBitmap on the screen via OpenGL. Especially as it seems I actually want to do less than is currently available - not more, i.e. I just want to go from a Bitmap in memory to a Texture as opposed to a Bitmap on disk to a Texture.

Is there another that way I can convert a TBitmap (that's not held in a file or resource) to a Texture? Or is there a way that I can just blat a TBitmap to the screen without even caring about whether it's a Texture or not?

Some thoughts...

1) glDrawPixels - can this be used to point to a TBitmap and then blat it to the screen somehow?

2) I would've thought the LoadTexture function from Textures.pas would basically end up with a TBitmap in RAM at some point, as it reads off disk? However, it doesn't really appear so... LoadTexture called LoadBMPTexture which eventually calls CreateTexture with a pointer to a chunk of data... and does code similar to below in 3.

3) What about something like this - it's loading from a resource, but could I miss out those steps somehow? Lines 2 and 5 are doing this I believe.
Code:
  1.   glGenTextures (1,ScreenTexture);
  2.   hBMP := LoadImage (GetModuleHandle (Nil),'ScreenTexture',IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  3.   if (hBMP <> 0) then
  4.   begin
  5.     GetObject (hBMP,SizeOf (BMP),@BMP);
  6.     glPixelStoreI (GL_UNPACK_ALIGNMENT,4);
  7.     glBindTexture (GL_TEXTURE_2D,ScreenTexture);
  8.     glTexParameterI (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  9.     glTexParameterI (GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
  10.     gluBuild2DMipmaps (GL_TEXTURE_2D,3,BMP.bmWidth,BMP.bmHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,BMP.bmBits);
  11.     DeleteObject (hBMP);
  12.   end;
4) Anything else?

At least I've learned a lot today - even if I've not done much that's actually productive.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Mär 27, 2007 23:48 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
If you have to, you can scale the picture up to power of two.
Simple solution, but problems because of the scaling.

Another solution is to increase the image size. For example if you have a 342x57 picture you size the bitmap to 512x128, leaving "white space". You have to adjust textur coordinates to use that texture but won't create that problems. This will not alter the picture, there will only be problems at the border of the picture because of rounding. In your case this can be solved by taking a border of 1 pixel in the picture and drawning the final texture with 1 pixel overlay in ortho.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Interesting progress...
BeitragVerfasst: So Apr 01, 2007 18:17 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
OK... I have been carrying on with this in my spare time. I really need to mix GDI and OpenGL for a short time in my project - I can't just abandon all my legacy code - so I need to be able to save a screen drawn with GDI and display it (correctly sized and positioned) while I am doing eye-candy OpenGL stuff on top of it...

I have made some interesting progress I think... I can now draw stuff in GDI to the TCanvas of a TForm, then save that information as a TBitmap and convert it to a Byte array that is then able to be passed to glDrawPixels and be rendered, in the correct size and position, in OpenGL orthographic projection.

However - now I'm on a learning-curve problem again - I can't seem to reset to perspective projection and draw what I was drawing over the background - so I'm wondering if someone might be able to assist me again in getting this right. Here is the entire code of the project - it is very simple. Once again, as before, when the application runs... you press the buttons along the bottom in order... to draw some GDI stuff, save that to a TBitmap and convert it for use with OpenGL, to start OpenGL rendering, to stop OpenGL rendering and replace the OpenGL scene with the one saved as a TBitmap in the first place...

Code:
  1.  
  2. unit MainForm;
  3.  
  4. interface
  5.  
  6. uses
  7.   OpenGL, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  8.   StdCtrls, ExtCtrls, ComCtrls;
  9.  
  10. const
  11.   { ClientWidth x ClientHeight x RGB. }
  12.   Pixels = 534 * 637 * 3;
  13.  
  14. type
  15.   TfrmMain = class(TForm)
  16.     bStartOpenGL: TButton;
  17.     bStopOpenGL: TButton;
  18.     bEnd: TButton;
  19.     bSaveAndConvert: TButton;
  20.     bDrawGDI: TButton;
  21.     Timer3: TTimer;
  22.     procedure FormCreate (Sender : TObject);
  23.     procedure bStartOpenGLClick(Sender: TObject);
  24.     procedure bStopOpenGLClick(Sender: TObject);
  25.     procedure bDrawGDIClick(Sender: TObject);
  26.     procedure bEndClick(Sender: TObject);
  27.     procedure bSaveAndConvertClick(Sender: TObject);
  28.     procedure Timer3Timer(Sender: TObject);
  29.   private
  30.     procedure SetOrthographicProjection;
  31.     procedure SetPerspectiveProjection;
  32.     procedure DrawBackground;
  33.     procedure DrawForeground;
  34.   public
  35.   end;
  36.  
  37.   PRGBArray = ^TRGBArray;
  38.   TRGBArray = array [0..533] of TRGBTriple;
  39.  
  40. var
  41.   frmMain : TfrmMain;
  42.   Base, Rotation, Changer : GLUInt;
  43.   ToPrint : String;
  44.   GMF : array [0..255] of GLYPHMETRICSFLOAT;
  45.   DC : HDC;
  46.   RC : HGLRC;
  47.   ScreenData : array [0..Pixels] of Byte;
  48.   ScreenBitmap : TBitmap;
  49.  
  50.   procedure glBindTexture (Target : GLEnum; Texture : GLUInt); stdcall; external OpenGL32;
  51.  
  52.  
  53. implementation
  54.  
  55.  
  56. {$R *.DFM}
  57.  
  58.  
  59. procedure BuildFont;
  60. var
  61.   Font : HFont;
  62. begin
  63.   Base := glGenLists (256);
  64.   Font := CreateFont (-12,-12,0,0,0,0,0,0,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_DONTCARE or DEFAULT_PITCH,'Arial');
  65.   SelectObject (DC,Font);
  66.   wglUseFontOutlines (DC,0,255,Base,0,0.2,WGL_FONT_POLYGONS,@GMF);
  67. end;
  68.  
  69.  
  70. procedure glPrint ( Text : String
  71.                   );
  72. begin
  73.   if (Text <> '') then
  74.   begin
  75.     glTranslatef (-0.22,0,0);
  76.     glPushAttrib (GL_LIST_BIT);
  77.       glListBase (base);
  78.       glCallLists (Length (Text),GL_UNSIGNED_BYTE,PChar (Text));
  79.     glPopAttrib;
  80.   end;
  81. end;
  82.  
  83.  
  84. procedure setupPixelFormat ( DC : HDC
  85.                            );
  86. const
  87.    pfd : TPIXELFORMATDESCRIPTOR = (
  88.         nSize : SizeOf (TPIXELFORMATDESCRIPTOR);
  89.         nVersion : 1;
  90.         dwFlags : PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
  91.         iPixelType : PFD_TYPE_RGBA;
  92.         cColorBits : 24;
  93.         cRedBits : 0;
  94.         cRedShift : 0;
  95.         cGreenBits : 0;
  96.         cGreenShift : 0;
  97.         cBlueBits : 0;
  98.         cBlueShift : 0;
  99.         cAlphaBits : 0;
  100.         cAlphaShift : 0;
  101.         cAccumBits : 0;
  102.         cAccumRedBits : 0;
  103.         cAccumGreenBits : 0;
  104.         cAccumBlueBits : 0;
  105.         cAccumAlphaBits : 0;
  106.         cDepthBits : 16;
  107.         cStencilBits : 0;
  108.         cAuxBuffers : 0;
  109.         iLayerType : PFD_MAIN_PLANE;
  110.         bReserved : 0;
  111.         dwLayerMask : 0;
  112.         dwVisibleMask : 0;
  113.         dwDamageMask : 0;);
  114. var
  115.   PixelFormat : Integer;
  116. begin
  117.    PixelFormat := ChoosePixelFormat (DC,@pfd);
  118.    if (pixelFormat = 0) then
  119.    begin
  120.      Exit;
  121.    end;
  122.  
  123.    if (SetPixelFormat (DC,PixelFormat,@pfd) <> True) then
  124.    begin
  125.      Exit;
  126.    end;
  127. end;
  128.  
  129.  
  130. procedure TfrmMain.FormCreate ( Sender : TObject
  131.                               );
  132. begin
  133.   DC := GetDC (frmMain.Handle);
  134.   SetupPixelFormat (DC);
  135.   RC := wglCreateContext (DC);
  136.   wglMakeCurrent (DC,RC);
  137.  
  138.   glShadeModel (GL_SMOOTH);
  139.   glClearColor (0,0,0,0);
  140.   glEnable (GL_DEPTH_TEST);
  141.   glHint (GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
  142.   glEnable (GL_LIGHT0);
  143.   glEnable (GL_LIGHTING);
  144.   glEnable (GL_COLOR_MATERIAL);
  145.   glPixelStorei (GL_UNPACK_ALIGNMENT,1);
  146.  
  147.   BuildFont;
  148.  
  149.   Rotation := 30;
  150.   Changer := 0;
  151.   ToPrint := '3';
  152.   glColor3f (1,0,0);
  153. end;
  154.  
  155.  
  156. procedure TfrmMain.bStartOpenGLClick ( Sender : TObject
  157.                                      );
  158. begin
  159.   { Commence OpenGL rendering... }
  160.   Timer3.Enabled := True;
  161. end;
  162.  
  163.  
  164. procedure TfrmMain.bStopOpenGLClick ( Sender : TObject
  165.                                     );
  166. begin
  167.   Timer3.Enabled := False;
  168.   { Replace what OpenGL has rendered with the saved TBitmap. }
  169.   frmMain.Canvas.Draw (0,0,ScreenBitmap);
  170.   ScreenBitmap.Free;
  171. end;
  172.  
  173.  
  174. procedure TfrmMain.bDrawGDIClick ( Sender : TObject
  175.                                  );
  176. begin
  177.   with frmMain.Canvas do
  178.   begin
  179.     SetBkMode (Handle,Transparent);
  180.     Pen.Color := clLime;
  181.     MoveTo (0,0);
  182.     LineTo (ClientWidth,0);
  183.     Pen.Color := clRed;
  184.     Pen.Width := 2;
  185.     Ellipse (10,10,100,100);
  186.     Pen.Color := clYellow;
  187.     Rectangle (100,100,200,300);
  188.     Pen.Color := clLime;
  189.     Pen.Width := 3;
  190.     MoveTo (75,75);
  191.     LineTo (400,125);
  192.     Pen.Color := clOlive;
  193.     MoveTo (300,50);
  194.     LineTo (50,400);
  195.     Pen.Color := clBlue;
  196.     Pen.Width := 3;
  197.     Rectangle (250,300,500,500);
  198.     Font.Name := 'Arial';
  199.     Font.Size := 20;
  200.     Font.Color := clWhite;
  201.     Font.Style := Font.Style + [fsBold];
  202.     TextOut (50,100,'Here is some text...');
  203.     Font.Color := clLime;
  204.     TextOut (20,400,'Here is some more text...');
  205.     Brush.Color := clYellow;
  206.     FillRect (Bounds (0,0,10,10));
  207.     FillRect (Bounds (0,ClientHeight - 10,10,10));
  208.     FillRect (Bounds (ClientWidth - 10,ClientHeight - 10,10,10));
  209.     FillRect (Bounds (ClientWidth - 10,0,10,10));
  210.     Brush.Color := clNone;
  211.   end;
  212. end;
  213.  
  214.  
  215. procedure TfrmMain.bSaveAndConvertClick ( Sender : TObject
  216.                                         );
  217. var
  218.   RowLoop, ColLoop, Index : Integer;
  219.   ScanLine : PRGBArray;
  220. begin
  221.   { Create Bitmap and copy the TForm's contents to it. }
  222.   ScreenBitmap := TBitmap.Create;
  223.   ScreenBitmap.PixelFormat := pf24bit;
  224.   ScreenBitmap.Width := frmMain.ClientWidth;
  225.   ScreenBitmap.Height := frmMain.ClientHeight;
  226.   ScreenBitmap.Canvas.CopyRect (ClientRect,Canvas,ClientRect);
  227.  
  228.   { Copy the TBitmap's pixels to an array of Byte that glReadPixels can use. }
  229.   Index := 0;
  230.   for RowLoop := ScreenBitmap.Height - 1 downto 0 do
  231.   begin
  232.     ScanLine := ScreenBitmap.ScanLine[RowLoop];
  233.     for ColLoop := 0 to ScreenBitmap.Width - 1 do
  234.     begin
  235.       ScreenData[Index] := ScanLine[ColLoop].rgbtRed;
  236.       ScreenData[Index + 1] := ScanLine[ColLoop].rgbtGreen;
  237.       ScreenData[Index + 2] := ScanLine[ColLoop].rgbtBlue;
  238.       Inc (Index,3);
  239.     end;
  240.   end;
  241. end;
  242.  
  243.  
  244. procedure TfrmMain.Timer3Timer ( Sender : TObject
  245.                                );
  246. begin
  247.   { Clear the screen. }
  248.   glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  249.   { Set up for 2D rendering... }
  250.   SetOrthographicProjection;
  251.   { Draw the background Bitmap... }
  252.   DrawBackground;
  253.   { Set up for 3D rendering... }
  254.   SetPerspectiveProjection;
  255.   { Draw the numbers in the foreground... }
  256.   DrawForeground;
  257.   { Draw the whole thing... }
  258.   SwapBuffers (wglGetCurrentDC);
  259. end;
  260.  
  261.  
  262. procedure TfrmMain.SetOrthographicProjection;
  263. begin
  264.   glViewport (0,0,ClientWidth,ClientHeight);
  265.   glMatrixMode (GL_PROJECTION);
  266.   glLoadIdentity;
  267.   gluOrtho2D (0,ClientWidth,0,ClientHeight);
  268.   glMatrixMode (GL_MODELVIEW);
  269.   glLoadIdentity;
  270. end;
  271.  
  272.  
  273. procedure TfrmMain.SetPerspectiveProjection;
  274. begin
  275.   glViewport (0,0,ClientWidth,ClientHeight);
  276.   glMatrixMode (GL_PROJECTION);
  277.   glLoadIdentity;
  278.   gluPerspective (45.0,ClientWidth / ClientHeight,0.1,100.0);
  279.   glMatrixMode (GL_MODELVIEW);
  280.   glLoadIdentity;
  281. end;
  282.  
  283.  
  284. procedure TfrmMain.DrawBackground;
  285. begin
  286.   { Start in the bottom-left corner. }
  287.   glRasterPos2i (0,0);
  288.   { Draw the saved Bitmap by pointing to the ScreenData array of Byte. }
  289.   glDrawPixels (ClientWidth,ClientHeight,GL_RGB,GL_UNSIGNED_BYTE,@ScreenData);
  290. end;
  291.  
  292.  
  293. procedure TfrmMain.DrawForeground;
  294. begin
  295.   Inc (Changer,5);
  296.  
  297.   if ((Changer = 360) and (ToPrint = '3')) then
  298.   begin
  299.     glColor3f (1,1,0);
  300.     ToPrint := '2';
  301.     Changer := 0;
  302.   end else
  303.   if ((Changer = 360) and (ToPrint = '2')) then
  304.   begin
  305.     glColor3f (0,1,0);
  306.     ToPrint := '1';
  307.     Changer := 0;
  308.   end else
  309.   if ((Changer = 360) and (ToPrint = '1')) then
  310.   begin
  311.     glColor3f (1,0,0);
  312.     ToPrint := '3';
  313.     Changer := 0;
  314.   end;
  315.  
  316.   glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  317.  
  318.   glTranslatef (0,-0.33,-1);
  319.   glRotatef (Rotation,0,1.0,0.0);
  320.   glRotatef (Sin (Changer / 600) * 10,0,1,0);
  321.   glRotatef (Sin (Changer / 600) * 10,1,0,0);
  322.   glPrint (ToPrint);
  323. end;
  324.  
  325.  
  326. procedure KillFont;
  327. begin
  328.   glDeleteLists (Base,256);
  329. end;
  330.  
  331.  
  332. procedure TfrmMain.bEndClick ( Sender : TObject
  333.                              );
  334. begin
  335.   KillFont;
  336.   Halt (0);
  337. end;
  338.  
  339.  
  340. end.
It is my SetOrthographicProjection (line 262) and SetPerspectiveProjection (line 273) procedures that I'm a bit concerned about - and how they work together. In my TTimer event handler that acts as the OpenGL drawing routine I call:

Code:
  1.   { Clear the screen. }
  2.   glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  3.   { Set up for 2D rendering... }
  4.   SetOrthographicProjection;
  5.   { Draw the background Bitmap... }
  6.   DrawBackground;
  7.   { Set up for 3D rendering... }
  8.   SetPerspectiveProjection;
  9.   { Draw the numbers in the foreground... }
  10.   DrawForeground;
  11.   { Draw the whole thing... }
  12.   SwapBuffers (wglGetCurrentDC);
If I leave all lines in, I just get my OpenGL 3D numbers counting down when I click the "Start OpenGL" button. If I remove the call to DrawForeground, then I see my saved background being rendered in OpenGL - I know this is working as I'd hoped because if I remove the call to DrawBackground I get a blank, black screen (expected) and if I count the loop up instead of down in line 230 of the main listing - I get the image inverted (again, expected)... the fact is - OpenGL is drawing it successfully.

BTW - at the moment - the DrawForeground procedure has a call to glClear in it - I would, obviously, expect this to not be there - but, if I don't put it in, I don't see my OpenGL numbers at all. So, as the code is right now - I understand why my background isn't being displayed - but if I remove the call to glClear, I see just the background - not the OpenGL numbers in the foreground! What I want to see - is my background and my foreground... so I think my question has now become a much simpler one:

How do I successfully move between orthographic and perspective projection - drawing things in OpenGL as I wish? or How can this code be altered so that I see my background and my foreground?

I would appreciate the extra bit of help - as I think I'm almost there to get what I want (need) to do for my project. I have included the source code once again.


Dateianhänge:
DpMSourceCode.zip [4.1 KiB]
316-mal heruntergeladen

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Success!
BeitragVerfasst: So Apr 01, 2007 23:11 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
Actually... I've just had a "Eureka Moment"... I changed: "glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);" just before drawing my foreground to be: "glClear (GL_DEPTH_BUFFER_BIT);" only and it works as I had expected. I now see:

Bild

Which means that...

1) I can draw GDI stuff to a TForm's TCanvas.
2) I can save the contents of that TCanvas as a TBitmap.
3) I can convert that TBitmap information to an array of Byte.
4) I can commence my OpenGL rendering phase.
5) I can use the array of Byte to pass to glDrawPixels in ortho mode.
6) I can switch to perspective mode and do my OpenGL eye-candy on top.

And it only took me a couple of weeks and about 18 forum entries asking dumb questions! Not bad, huh?

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 28 Beiträge ]  Gehe zu Seite Vorherige  1, 2
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.013s | 16 Queries | GZIP : On ]