Results 1 to 3 of 3

Thread: Please, tell me my error?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    5

    Please, tell me my error?

    Hello! I am beginner in OpenGL. I use Delphi+OpenGL. In my small programm one moment don't work.
    In event KeyDown procedure InvalidateRect is. But all opengl programm don't work after this procedure. All scene don't change. Help me please.
    This is programm:
    Code :
    program test_game;
     
    uses
      Windows,
      Messages,
      OpenGL;
     
    var
      y: Single;
      wid, heig: cardinal;
      modul_id: HWND;
      hlr: HGLRC;
      dc: HDC;
      my_paint: TPaintStruct;
      WindowClass: TWndClass;
      Handle: HWND;
      msg: TMsg;
      default_screen: TDevMode;
      old_wid, old_heig, old_bits: integer;
     
    procedure DoExit;
    begin
      Halt;
    end;
     
    procedure SetDCPixelFormat(hd: HDC);
    var
      pfd: TPixelFormatDescriptor;
      nPixelFormat: integer;
    begin
      FillChar(pfd, sizeof(pfd), 0);
      pfd.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
      nPixelFormat:=ChoosePixelFormat(hd, @pfd);
      SetPixelFormat(hd, nPixelFormat, @pfd);
    end;
     
    procedure start;
    begin
       glViewPort(0, 0, wid, heig);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity;
       glFrustum(-1, 1, -1, 1, 3, 10);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity;
       glTranslatef(0.0, 0.0, -5.0);
       glRotatef(30.0, 1.0, 0.0, 0.0);
       glRotatef(70.0, 0.0, 1.0, 0.0);
    end;
     
    function WindowProc(Hwn,msg,wpr,lpr: longint): longint; stdcall;
    var
      modes: TDevMode;
      hdcscreen: HDC;
    begin
      result:=defwindowproc(hwn,msg,wpr,lpr);
      if msg=wm_Create then
      begin
        y:=0;
        hdcscreen:=GetDC(0);
        old_wid:=GetDeviceCaps(hdcscreen, HORZRES);
        old_heig:=GetDeviceCaps(hdcscreen, VERTRES);
        old_bits:=GetDeviceCaps(hdcscreen, BITSPIXEL);
        ReleaseDC(0, hdcscreen);
        DeleteDC(hdcscreen);
     
        modes.dmBitsPerPel:=32;
        modes.dmPelsWidth:=800;
        modes.dmPelsHeight:=600;
        modes.dmDisplayFrequency:=0;
        modes.dmFields:=DM_BITSPERPEL or DM_PELSWIDTH or
        DM_PELSHEIGHT or DM_DISPLAYFLAGS;
        wid:=modes.dmPelsWidth;
        heig:=modes.dmPelsHeight;
        ChangeDisplaySettings(Modes, CDS_FULLSCREEN);
     
        dc:=GetDC(Hwn);
        SetDCPixelFormat(dc);
        hlr:=wglCreateContext(dc);
        wglMakeCurrent(dc, hlr);
        glClearColor(0.0,0.0,0.0,1.0);
        glEnable(GL_DEPTH_TEST);
        //glEnable(GL_LIGHTING);
        //glEnable(GL_LIGHT0);
        //glEnable(GL_COLOR_MATERIAL);
        ReleaseDC(Hwn, dc);
      end;
      if msg=wm_destroy then
      begin
        default_screen.dmPelsWidth:=old_wid;
        default_screen.dmPelsHeight:=old_heig;
        default_screen.dmFields:=DM_BITSPERPEL or DM_PELSWIDTH or
        DM_PELSHEIGHT or DM_DISPLAYFLAGS;
        default_screen.dmBitsPerPel:=old_bits;
        default_screen.dmDisplayFrequency:=0;
        ChangeDisplaySettings(default_screen, CDS_FULLSCREEN);
     
        wglDeleteContext(hlr);
        DeleteDC(dc);
        DoExit;
      end;
      if msg=wm_Paint then
      begin
        dc:=BeginPaint(Hwn, my_paint);
        start;
        glRotatef(y,0.0,0.0,1.0);
     
        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
          glColor3f(1.0,0.0,0.0);
          glPointSize(10);
          glEnable(GL_POINT_SMOOTH);
          glPointSize(10);
          glBegin(GL_POINTS);
            glVertex3f(0,0,0);
          glEnd;
     
          glColor3f(0.4,0.4,0.0);
          glBegin(GL_QUADS);
            glNormal3f(0,-1,0);
            glVertex3f(-1,-1,1);
            glVertex3f(-1,-1,-1);
            glVertex3f(1,-1,-1);
            glVertex3f(1,-1,1);
          glEnd;
          glColor3f(0.0,0.4,0.4);
          glBegin(GL_QUADS);
            glNormal3f(0,0,-1);
            glVertex3f(-1,-1,-1);
            glVertex3f(1,-1,-1);
            glVertex3f(1,1,-1);
            glVertex3f(-1,1,-1);
          glEnd;
          glBegin(GL_QUADS);
            glNormal3f(1,0,0);
            glVertex3f(1,-1,-1);
            glVertex3f(1,1,-1);
            glVertex3f(1,1,1);
            glVertex3f(1,-1,1);
          glEnd;
        SwapBuffers(dc);
        EndPaint(Hwn, my_paint);
        wglMakeCurrent(dc, 0);
        ReleaseDC(Hwn, dc);
      end;
      if msg=wm_KeyDown then
      begin
        if wpr=VK_ESCAPE then
          DoExit;
        y:=y+30;
        InvalidateRect(hwn, nil, false);
      end;
    end;
     
    begin
      modul_id:=GetModuleHandle(nil);
      WindowClass.style:=CS_HRedraw or CS_VRedraw;
      WindowClass.lpfnWndProc:=@windowproc;
      WindowClass.hInstance:=modul_id;
      WindowClass.lpszClassName:='main';
      WindowClass.hCursor:=LoadCursor(0, IDC_ARROW);
     
      RegisterClass(WindowClass);
      Handle:=CreateWindowEx(WS_EX_TOPMOST, 'main', '', ws_visible or ws_Popup or WS_MAXIMIZE, cw_UseDefault, cw_UseDefault, cw_UseDefault, cw_UseDefault,0,0,modul_id,nil);
      ShowWindow(Handle, SW_Show);
      UpdateWindow(Handle);
     
      while (GetMessage(msg,0,0,0)) do
      begin
        translatemessage(msg);
        dispatchmessage(msg);
      end;
    end.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Please, tell me my error?

    Actually your program will not draw anything after first wm_Paint message is processed because of the wglMakeCurrent(dc, 0) line. The InvalidateRect simply shows this problem by clearing the window.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    5

    Re: Please, tell me my error?

    thank you! I understand my error!

Similar Threads

  1. Shader Compile Error: ERROR: 0:1: '' : syntax error #version
    By Blakeasd in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 07-25-2013, 07:35 PM
  2. Replies: 2
    Last Post: 05-31-2013, 01:06 PM
  3. ERROR: 0:17:'f' : syntax error parse error
    By hopeless in forum OpenGL: GLSL
    Replies: 1
    Last Post: 08-23-2010, 01:05 PM
  4. Replies: 1
    Last Post: 09-24-2007, 04:02 AM
  5. Replies: 3
    Last Post: 02-07-2003, 05:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean