Drawing Delphi OpenGL

I configure my window as follows:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, form1.Width, form1.height, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);

And my drawing procedure looks like this:

tempdist:=0.3 / distance(i,0,1,2);
xunit:=1 div 90;
zunit:=1 div 74;
glBegin(GL_LINE_LOOP);
case players[i].isteam of
2:glcolor3f(1.0,0.0,0.0); //Terrorist
3:glcolor3f(0.0,0.0,1.0); //Counter-Terrorist
end;
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit+tempdist);
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit+tempdist);
glEnd();
SwapBuffers(wglGetCurrentDC);

No sign of painting at all. Any help?

+3
source share
3 answers

As we do not know what the value of tax is from your code, is it possible that you go beyond the cutoff?

Getting your first work with OpenGL quite often takes half the battle. I suggest going to DelphiGL and finding an example that is close to what you want and working from there. The site is in German by default, but there is an extensive English translation. In particular, they have a useful set of default templates.

0
source

, , opengl, :

  • glViewport (0, 0, Width, Height);// OpenGL
  • , glortho ( opengl?)
  • thetax thetaz?

dc:

 fdc:=getdc(<windowhandle of control we are displaying on  >);
 FRC := wglCreateContext(FDC);
 b:=wglMakeCurrent(FDC, FRC);

 wglMakeCurrent(0, 0); 
 wglDeleteContext(frc);  
0

.

, , DC, , , , .

http://glscene.cvs.sourceforge.net/viewvc/glscene/Source/Platform/GLWin32Viewer.pas?view=log, , GLScene , OpenGL.

DC CreateParams + :

   with Params do begin
      Style:=Style or WS_CLIPCHILDREN or WS_CLIPSIBLINGS;
      WindowClass.Style:=WindowClass.Style or CS_OWNDC;
   end;

DC CreateWnd DestroyWnd

After you have DC, you need to make sure that PixelFormat supports OpenGL +, has the necessary information:

const pfd: PIXELFORMATDESCRIPTOR = (
    nSize: sizeof(PIXELFORMATDESCRIPTOR);
    nVersion: 1;                       // version
    dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
    iPixelType: PFD_TYPE_RGBA;
    cColorBits: 24;                    // 24-bit color depth
    cRedBits: 0;
    cRedShift: 0;
    cGreenBits: 0;
    cGreenShift: 0;
    cBlueBits: 0;
    cBlueShift: 0;
    cAlphaBits: 8;                     // alpha bits
    cAlphaShift: 0;
    cAccumBits: 0;                     // accumulation buffer
    cAccumRedBits: 0;
    cAccumGreenBits: 0;
    cAccumBlueBits: 0;
    cAccumAlphaBits: 0;
    cDepthBits: 32;                    // z-buffer
    cStencilBits: 16;                  // stencil buffer
    cAuxBuffers: 0;                    // auxiliary buffer
    iLayerType: PFD_MAIN_PLANE;        // main layer
    bReserved: 0;
    dwLayerMask: 0;
    dwVisibleMask: 0;
    dwDamageMask: 0
);
var
  pf: Integer;
begin
  pf := ChoosePixelFormat(dc, @pfd);
  if not SetPixelFormat(dc, pf, @pfd) then
    Assert(false);//failed, could retry with other settings 
  rc := wglCreateContext(dc);
  if not wglMakeCurrent(dc, rc) then
    Assert(false);// failed
  // we should now have a rc so to test, we'll just clear
  glClearColor(1, 0.5, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT);
  // If we're double-buffered, then swap
  SwapBuffers(dc);
  wglMakeCurrent(0, 0);

After you have finished using RC, you should also clear it by calling wglDeleteContext.

0
source

Source: https://habr.com/ru/post/1733678/


All Articles