
Původně odeslal
stealth

Původně odeslal
Anduril

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