Citace Původně odeslal stealth
Citace Původně odeslal Anduril
Citace Původně odeslal Lando
Nevite nekdo, jak nakreslit caru pomoci DirectDraw?
Nebo aspon odkaz...
Nebo neco...
Pokud víš, jak mazat obraz, tak akorát zadáš RECT na velikost tvé čáry a případně změníš barvu. A nebo můžeš využít DC...a pomocí GDI nakreslit čáru. - z paměti to nevím, co to je za fce, ale najdeš to v MSDN.
tim rect, myslis co ? RECT je struktura
mam pocit, ze neco takoveho
typedef RECT {
int left,right,top,bottom;
}
pouziva se pri kresleni obdelniku, treba tak
RECT rect;
Rectangle(hdc, rect.left, rect.top, rect.right, rect.top);
... ee - myslel jsem to takto (C++ a DirectDraw) - kód na vykreslení libovolné čáry:
Kód:
/*
  BSurface::FillArea (...)
    - fill area (x,y,w,h) with color
*/
void BSurface::FillArea (int x, int y, int w, int h, int color)
{
  DDBLTFX ddBltFx;
  RECT    rDst;

  //Process
  rDst.left = x;
  rDst.top  = y;
  rDst.right = x + w;
  rDst.bottom = y + h;
  
  //Prepare colors
  ddBltFx.dwSize = sizeof(DDBLTFX);
  ddBltFx.dwFillColor = color;
  
  //Fill surface
  lpDDSurface->Blt(&rDst, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddBltFx);
}

/*
  BSurface::Line (...)
    - draw line from x1,y1 to x2,y2 with color
*/
void BSurface::Line (int x1, int y1, int x2, int y2, int color)
{
  double xStep, yStep, dx, dy;
  int    xLength, yLength, xCount, yCount, tempV;

  //Process
    //Horizontal line
    if(y1==y2){
      FillArea (x1, y1, x1 + x2, 1, color);
    }
    //Vertical line
    else if(x1==x2){
      FillArea (x1, y1, 1, y1 + y2, color);
    }
    //Any other line
    else {
      xLength = abs(x2 - y1);
      yLength = abs(y2 - y1);

      if(xLength==0) 
        FillArea (x1, y1, 1, y1 + y2, color); 
      else if(yLength==0) 
        FillArea (x1, y1, x1 + x2, 1, color);
      else if(xLength > yLength) {
   
        if(x1 > x2) {
          tempV = x1; x1 = x2; x2 = tempV;
          tempV = y1; y1 = y2; y2 = tempV;
        }

        yStep = (double)(y2 - y1) / (double)(x2 - x1);
        dy = y1;
  
        //Draw it
        for&#40;xCount = x1; xCount <= x2; xCount++&#41; &#123;
          FillArea &#40;xCount, &#40;int&#41;dy, 1, 1, color&#41;;
          dy += yStep;
        &#125;
                
      &#125;
      else &#123;
      
        if&#40;y1 > y2&#41; &#123;
          tempV = x1; x1 = x2; x2 = tempV;
          tempV = y1; y1 = y2; y2 = tempV;  	
        &#125;

        xStep = &#40;double&#41;&#40;x2 - x1&#41; / &#40;double&#41;&#40;y2 - y1&#41;;
        dx = x1;

        //Draw it
        for&#40;yCount = y1; yCount <= y2; yCount++&#41; &#123;
          FillArea &#40;&#40;int&#41;dx, yCount, 1, 1, color&#41;;
          dx += xStep;
        &#125;        
      &#125;
    &#125;   
&#125;
A nebo třeba takto (C a DirectDraw + GDI):
Kód:
void DrawLine&#40;LPDIRECTDRAWSURFACE surface, int x1, int y1, int x2, int y2, DWORD color&#41;
&#123;
   HPEN pen;
   HDC  t_dc;
   
   surface->lpVtbl->GetDC&#40;surface, &t_dc&#41;;
   if&#40;t_dc == NULL&#41; return; 
   
   pen = CreatePen&#40;PS_SOLID, 0, color&#41;;
   SelectObject&#40;t_dc, pen&#41;;
   
   MoveToEx&#40;t_dc, x1, y1, NULL&#41;;
   LineTo&#40;t_dc, x2, y2&#41;;
   
   surface->lpVtbl->ReleaseDC&#40;surface, t_dc&#41;;
   DeleteObject&#40;pen&#41;;   
&#125;
.. Mělo by to být dobře, doufám.