OpenGL program doesn't works - where is the error? lazarus / 70-OpenGL ---------------------------------------------------------------------- Milsa · 2014-02-09 10:29 This program must show green triangle and "Esc" quits the program. It does not works. Please help me. Program is from czech page: http://i.iinfo.cz/r/photos/opengl/opengl_02_1.html This is example from article: http://www.root.cz/clanky/opengl-2-syntaxe-funkci/ My program is rewritten to Free Pascal. Edit: I have glut32.dll in program directory too. ---------------------------------------------------------------------- BlueIcaro · 2014-02-09 12:20 Hi, you don't tell us what is exactly the problem. If you have any error, or you don't show the triangle. Please, give more information. By the way, try to study this easy  example, you should have "glut32.dll" on your path or in the same folder of your application. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program simpleshape; {$mode objfpc}{$H+} uses  gl, glu, glut; const  AppWidth = 640;  AppHeight = 480; procedure InitializeGL;begin  glClearColor(0.18, 0.20, 0.66, 0);end; procedure DrawGLScene; cdecl;begin  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);   glLoadIdentity;  glTranslatef(0, 0, -5);   glBegin(GL_TRIANGLES);    glColor3f(1, 0, 0);    glVertex3f(-1, -1, 0);     glColor3f(0, 1, 0);    glVertex3f(1, -1, 0);     glColor3f(0, 0, 1);    glVertex3f(0, 1, 0);  glEnd;    glutSwapBuffers;end; procedure ReSizeGLScene(Width, Height: Integer); cdecl;begin  if Height = 0 then    Height := 1;   glViewport(0, 0, Width, Height);  glMatrixMode(GL_PROJECTION);  glLoadIdentity;  gluPerspective(45, Width / Height, 0.1, 1000);   glMatrixMode(GL_MODELVIEW);  glLoadIdentity;end; procedure GLKeyboard(Key: Byte; X, Y: Longint); cdecl;begin  if Key = 27 then  Halt(0);end; procedure glutInitPascal(ParseCmdLine: Boolean);var  Cmd: array of PChar;  CmdCount, I: Integer;begin  if ParseCmdLine then    CmdCount := ParamCount + 1  else    CmdCount := 1;  SetLength(Cmd, CmdCount);  for I := 0 to CmdCount - 1 do    Cmd[I] := PChar(ParamStr(I));  glutInit(@CmdCount, @Cmd);end; var  ScreenWidth, ScreenHeight: Integer;begin  glutInitPascal(True);  glutInitDisplayMode(GLUT_DOUBLE or GLUT_RGB or GLUT_DEPTH);  glutInitWindowSize(AppWidth, AppHeight);  ScreenWidth := glutGet(GLUT_SCREEN_WIDTH);  ScreenHeight := glutGet(GLUT_SCREEN_HEIGHT);  glutInitWindowPosition((ScreenWidth - AppWidth) div 2, (ScreenHeight - AppHeight) div 2);  glutCreateWindow('OpenGL Tutorial :: Simple Shape');   InitializeGL;   glutDisplayFunc(@DrawGLScene);  glutReshapeFunc(@ReSizeGLScene);  glutKeyboardFunc(@GLKeyboard);   glutMainLoop;end.  /BlueIcaro ---------------------------------------------------------------------- Milsa · 2014-02-09 13:58 My program opens console window and black opengl window and it is all. Your example works. I will compare these 2 codes and I will find error in my code. Thank you very much. ---------------------------------------------------------------------- Leledumbo · 2014-02-09 14:33 You did something really wrong: escaping the type safety Code: [Select]glutDisplayFunc(TGlutVoidCallback(@onDisplay)); glutReshapeFunc(TGlut2IntCallback(@onResize)); I don't have any idea how TGlutVoidCallback and TGlut2IntCallback are declared, but they're declared wrong. glut callbacks expect cdecl routines while what you have is the default (register) routine. Remove the typecast and the compiler will give proper error message. The correct fix is to declare the callbacks as cdecl. ---------------------------------------------------------------------- Milsa · 2014-02-09 20:54 Thank you all. Problem is "cdecl". I did not know "cdecl". My program works.