Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Initializing OpenGL...

  1. #1

    Initializing OpenGL...

    I'm just starting out with OpenGL, and I've got some code here that's giving me some trouble. I've got the proper .dlls for OpenGL and GLUT, so I'm sure that's not the problem. What happens is that I get an exception (access violation, etc) when I try to run it. I'm pretty sure the problem lies in the initialization of the window:

    Code:
    unit Main;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OpenGL, Glut;
    
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormActivate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      w,h: GLint;
    
    implementation
    
    {$R *.dfm}
    
    procedure SetRenderContext;
    begin
      glClearColor(0.9,0.4,0.2,1.0);
    end;
    
    procedure RenderIt; cdecl;
    begin
      glClear(GL_COLOR_BUFFER_BIT);
      glutSwapBuffers;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      w := 640;
      h := 480;
      glutInitDisplayMode(GLUT_DOUBLE or GLUT_RGBA);
      glutInitWindowSize(w,h);
      glutInitWindowPosition((Screen.Width-Form1.Width) div 2,(Screen.Height-Form1.Height) div 2);
      glutCreateWindow('Generic Window');
      glutDisplayFunc(RenderIt);
    end;
    
    procedure TForm1.FormActivate(Sender: TObject);
    begin
      SetRenderContext;
      glutMainLoop;
    end;
    
    end.
    I'm sure not all of that is needed, but I thought that I should post it all for completeness.

    Thanks in advance!
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  2. #2

    Initializing OpenGL...

    i dont think you can combine the glut commands you use from within a form. Maybe you can take a look a the courses available on http://nehe.gamedev.net. They are also available for delphi. Or take a look at http://www.sulaco.co.za.
    http://3das.noeska.com - create adventure games without programming

  3. #3

    Initializing OpenGL...

    I think you need to turn off certain errors in Delphi to use Glut... no clue if they improved it now, but a long time ago I tried using Glut and ran into a lot of problems :-x
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  4. #4

    Initializing OpenGL...

    Nevermind! I managed to locate the line that I need:

    Code:
    glutInit&#40;MS_LIB&#41;;
    Thanks anyways. :)

    EDIT
    Is there a way to set a procedure to be called or something that will allow me to close the Form after the OpenGL window has been closed? It's pretty annoying to have to close both windows each time I run a program. :P
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  5. #5

    Initializing OpenGL...

    you should not combine glut procedures together with a form. glut is for use with a console like program. That wont leave you with an open form. But if you want to use it with a form you could call application.terminate directly after your glutmainloop.
    http://3das.noeska.com - create adventure games without programming

  6. #6

    Initializing OpenGL...

    you should use the form template from sulaco if u want to draw on forms, i sent in a opengl 1.5 updated version to him and its on the site now. that works really well

  7. #7

    Initializing OpenGL...

    Quote Originally Posted by noeska
    you should not combine glut procedures together with a form. glut is for use with a console like program. That wont leave you with an open form. But if you want to use it with a form you could call application.terminate directly after your glutmainloop.
    Thanks for the advice. I recreated the program as a console application, but I'm still having the same problem. This time the console window stays active after I close the OpenGL window. Arg! :(

    I'll supply the code just in case I'm doing something wrong:

    Code:
    var
      w,h&#58; GLint;
    
    procedure Startup;
    begin
      glClearColor&#40;0.9,0.4,0.2,1.0&#41;;
    end;
    
    procedure Render; cdecl;
    begin
      glClear&#40;GL_COLOR_BUFFER_BIT&#41;;
      glutSwapBuffers;
    end;
    
    begin
      w &#58;= 640;
      h &#58;= 480;
      glutInit&#40;MS_LIB&#41;;
      glutInitDisplayMode&#40;GLUT_DOUBLE or GLUT_RGBA&#41;;
      glutInitWindowSize&#40;w,h&#41;;
      glutInitWindowPosition&#40;100,100&#41;;
      glutCreateWindow&#40;'Generic Window!'&#41;;
      glutDisplayFunc&#40;Render&#41;;
      Startup;
      glutMainLoop;
    end.
    Thanks in advance!
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  8. #8

    Initializing OpenGL...

    i dont know anything about glut but shouldnt it look more like...


    [code]
    begin
    {.. setup gl.. }

    while not CanClose do
    Begin
    {.. render ..}
    end;

    {.. destroy gl.. }
    end;//console closes here

  9. #9

    Initializing OpenGL...

    Quote Originally Posted by tux
    [code]
    begin
    {.. setup gl.. }

    while not CanClose do
    Begin
    {.. render ..}
    end;

    {.. destroy gl.. }
    end;//console closes here
    Nope. glutMainLoop() does the loop, and calls the glutDisplayFunc() specified when it comes time to render. Conveinent, no? :)

    Also: It seems that when I include glut32.dll in the same directory as the .exe, the console window closes when the OpenGL window closes. Otherwise, the console window remains active. Weirdness.
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  10. #10

    Initializing OpenGL...

    on this site you will find some delphi glut examples: http://hjem.get2net.dk/mithrandir/OpenGL/opengl.html
    If you are anoyed with windows staying open you might want to use the sulaco templates. Either the one with form or the one without the form.
    http://3das.noeska.com - create adventure games without programming

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •