DGL
https://delphigl.com/forum/

Jedi SDL + dglOpenGL.pas
https://delphigl.com/forum/viewtopic.php?f=19&t=3765
Seite 1 von 1

Autor:  Gast [ Mo Feb 07, 2005 13:09 ]
Betreff des Beitrags:  Jedi SDL + dglOpenGL.pas

I tried using dglOpenGL.pas with the SDL demos.
Replacing the unit OpenGL12.pas with dglOpenGL.pas and making the required changes so it compiles.
When running the application, as soon as any OpenGL call is made I get a access violation.
Anyone have a idea of what is the cause of this and how it can be fixed?

Autor:  sniper [ Mo Feb 07, 2005 13:28 ]
Betreff des Beitrags: 

Code:
  1.  
  2. unit Unit1;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs, dglopengl;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure FormDestroy(Sender: TObject);
  14.     procedure FormResize(Sender: TObject);
  15.     procedure FormPaint(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.     procedure glInit();
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.   mydc,myrc:cardinal;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. procedure Tform1.glInit();
  32. begin
  33.   glClearColor(0.3, 0.3, 0.3, 0.0);        // Black Background
  34.   glShadeModel(GL_SMOOTH);                 // Enables Smooth Color Shading
  35.   glClearDepth(1.5);                       // Depth Buffer Setup
  36.   glEnable(GL_DEPTH_TEST);
  37.   glDepthFunc (GL_LEQUAL);
  38. //  glEnable( GL_CULL_FACE );
  39. //  glCullFace( GL_FRONT );
  40.   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   //Realy Nice perspective calculations
  41.   glEnable(GL_TEXTURE_2D);                     // Enable Texture Mapping
  42.   wglSwapIntervalEXT(0);
  43. end;
  44.  
  45. procedure TForm1.FormCreate(Sender: TObject);
  46. begin
  47.  mydc := getdc(handle);
  48.  InitOpenGL();
  49.  myrc := CreateRenderingContext(mydc,[opDoublebuffered],32,24,0,0,0,0);
  50.  ActivateRenderingContext(mydc, myrc);
  51.  glInit();
  52. end;
  53.  
  54. procedure TForm1.FormDestroy(Sender: TObject);
  55. begin
  56.  DeactivateRenderingContext;
  57.  DestroyRenderingContext(myrc);
  58.  releasedc(handle,mydc);
  59. end;
  60.  
  61. procedure TForm1.FormResize(Sender: TObject);
  62. begin
  63.  if Height=0 then Height:=1;
  64.  
  65.   glViewport(0, 0, Width, Height);    // Set the viewport for the OpenGL window
  66.   glMatrixMode(GL_PROJECTION);        // Change Matrix Mode to Projection
  67.    glLoadIdentity();                   // Reset View
  68.     gluPerspective(45.0, Width/Height, 1.0, 1000.0);  // Do the perspective calculations. Last value = max clipping depth
  69.  
  70.   glMatrixMode(GL_MODELVIEW);         // Return to the modelview matrix
  71.    glLoadIdentity();                   // Reset View
  72.  
  73.    //if needed a faster feedback
  74.    OnPaint(self);
  75. end;
  76.  
  77. procedure TForm1.FormPaint(Sender: TObject);
  78. begin // this is only an alternative....OnIdle for intensiv drawing
  79.  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  80.    glLoadIdentity();
  81.    //--draw the scene
  82.  
  83.    //--draw then scene
  84.  SwapBuffers(mydc);
  85. end;
  86.  
  87. end.
  88.  

Autor:  Gast [ Mo Feb 07, 2005 13:40 ]
Betreff des Beitrags: 

Thank you, but I create the window using SDL calls.
What I did notice is this call
ActivateRenderingContext(mydc, myrc);

I don't have this in my code.
So does anyone know how I can extract the DC and HDC from SDL for use in this call?

Autor:  sniper [ Mo Feb 07, 2005 15:32 ]
Betreff des Beitrags: 

Zitat:
ActivateRenderingContext(mydc, myrc);

Without this line you can´t go on, because that is the place where all the functions pointer of OpenGL library are loaded. That is the reason why you get "Access violation" message, all pointers are = NIL. So any call to glXXX is a Access violation itself.
And sorry i can´t help you, have no knowlege on SDL.

Autor:  Lossy eX [ Mo Feb 07, 2005 15:38 ]
Betreff des Beitrags: 

Phobeus made this Tutorial about SDL and OpenGL. There are some sources. May it can helps.

Autor:  Gast [ Mo Feb 07, 2005 15:52 ]
Betreff des Beitrags: 

Your answer is good enough, thanks a bundel.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/