Recent

Author Topic: [solved] OpenGL and Mac OS X 10.5.8  (Read 10640 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
[solved] OpenGL and Mac OS X 10.5.8
« on: December 07, 2009, 06:18:33 am »
Hi all,

I have converted a simple opengl example to the fpc but the window does not appear on the screen. When i execute the application from shell i get the following message.

CTLoader
Toolbar has not been tested on this version.
Toolbar bundle will not be loaded.

The code seems working, here is the code that i am testing.
Thanks

//---------------------------
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, glu, glut, gl;

implementation

procedure square;
begin
    glBegin(GL_QUADS); //begin the four sided shape
    glVertex3f(-0.5, -0.5, 0.0); //first corner at -0.5, -0.5
    glVertex3f(-0.5, 0.5, 0.0); //second corner at -0.5, 0.5
    glVertex3f(0.5, 0.5, 0.0); //third corner at 0.5, 0.5
    glVertex3f(0.5, -0.5, 0.0); //fourth corner at 0.5, -0.5
    glEnd(); //end the shape we are currently working on
end;

procedure display;cdecl;
begin
    glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
    glClear (GL_COLOR_BUFFER_BIT); //Clear teh Color Buffer (more buffers later on)
    glLoadIdentity();  //load the Identity Matrix
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
    square;
    glFlush(); //flush it all to the screen
end;

begin
    glutInit(@argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowSize(800,600);
    glutInitWindowPosition (100, 100);
    glutCreateWindow('Example');
    glutDisplayFunc(@display);

    glutMainLoop;
end.                        

« Last Edit: December 07, 2009, 04:49:29 pm by IndianaJones »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: OpenGL and Mac OS X 10.5.8
« Reply #1 on: December 07, 2009, 09:16:03 am »

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: OpenGL and Mac OS X 10.5.8
« Reply #2 on: December 07, 2009, 02:38:27 pm »

Thanks @skalogryyz for the link, i uninstalled the mentioned application. Now I havent got that error message. But the mainwindow doesnt appear on the screen.
hereis the backtrace, and it seems okey.
Also here is the original application source link.
http://www.swiftless.com/tutorials/opengl/window.html

#0  0x9029b286 in mach_msg_trap ()
#1  0x902a2a7c in mach_msg ()
#2  0x90f1fe7e in CFRunLoopRunSpecific ()
#3  0x90f20aa8 in CFRunLoopRunInMode ()
#4  0x91ded2ac in RunCurrentEventLoopInMode ()
#5  0x91ded0c5 in ReceiveNextEventCommon ()
#6  0x91decf39 in BlockUntilNextEventMatchingListInMode ()
#7  0x905b26d5 in _DPSNextEvent ()
#8  0x905b1f88 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#9  0x905aaf9f in -[NSApplication run] ()
#10 0x3e023307 in glutMainLoop ()
#11 0x0022ee1a in GLUT_GLUTMAINLOOP ()
#12 0x00013b0e in fpc_initializeunits ()
#13 0x0001c745 in SYSTEM_FPC_SYSTEMMAIN$LONGINT$PPCHAR$PPCHAR ()
#14 0x0000235b in _start ()
#15 0x00002289 in start ()

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: OpenGL and Mac OS X 10.5.8
« Reply #3 on: December 07, 2009, 02:57:43 pm »
why are you implementing the PROGRAM as a UNIT? (what's the program's text, btw?)

i wonder if it's a bug in FPC, that allows begin..end. in unit declaration (or is it some macpascal compat feature?!)

here's code of the program, it runs fine (see the screenshot). Hope it works for you, let us know about the results. Thanks.

Code: [Select]
program Project1;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, glu, glut, gl;


procedure square;
begin
    glBegin(GL_QUADS); //begin the four sided shape
    glVertex3f(-0.5, -0.5, 0.0); //first corner at -0.5, -0.5
    glVertex3f(-0.5, 0.5, 0.0); //second corner at -0.5, 0.5
    glVertex3f(0.5, 0.5, 0.0); //third corner at 0.5, 0.5
    glVertex3f(0.5, -0.5, 0.0); //fourth corner at 0.5, -0.5
    glEnd(); //end the shape we are currently working on
end;

procedure display;cdecl;
begin
    glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
    glClear (GL_COLOR_BUFFER_BIT); //Clear teh Color Buffer (more buffers later on)
    glLoadIdentity();  //load the Identity Matrix
    //gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
    square;
    glFlush(); //flush it all to the screen
end;

begin
    glutInit(@argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowSize(800,600);
    glutInitWindowPosition (100, 100);
    glutCreateWindow('Example');
    glutDisplayFunc(@display);

    glutMainLoop;
end.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: OpenGL and Mac OS X 10.5.8
« Reply #4 on: December 07, 2009, 04:37:38 pm »

@skalogryyz, yep you absolutely right. I missed the "program" header at the program thats why it is not working. By the way I wrote this small opengl example in the morning (nearly four oclock) with sleepy eyes.
Anyway thanks.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: [solved] OpenGL and Mac OS X 10.5.8
« Reply #5 on: December 08, 2009, 12:24:02 am »

Hi,

Can someone translate this c procedure to pascal?
Thanks.

void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: [solved] OpenGL and Mac OS X 10.5.8
« Reply #6 on: December 08, 2009, 08:55:07 am »
void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}
OpenGL code is the easiest to port from C to Pascal. Though Pascal code won't need type casting.
Code: [Select]
procedure reshape(w,h: Integer);
begin
  glViewport(0,0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPespective(60, w/h, 1, 100); //todo: check that h <> 0
  glMatrixMode(GL_MODELVIEW);
end;

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: [solved] OpenGL and Mac OS X 10.5.8
« Reply #7 on: December 08, 2009, 10:53:26 am »

@skalogryyz
In the example, c type casting distracted my mind.
Thanks for the explanation also.

 

TinyPortal © 2005-2018