PDA

Click to See Complete Forum and Search --> : graphics, c++ newbie


DiGiTaIErRoR
Oct 26th, 2001, 01:38 PM
I'm new to c++ and as such I don't know a lot... especially about graphics in c++.

I have a program in VB which I'd like to convert to C++ for obvious speed reasons, it uses the .line function of a picture box and also has a setting for SetPixelV API which is incredibly faster(usually 4-5 times). I can handle to math part but I don't know how to draw the x, y grids. I think the h file is grafix, but I'm not sure. And even after I include that I don't know what to use to actually draw the points, and hopefully lines. My program makes 3d spirographs, along with lighting, as you can imagine this is slow in VB.

The more source you could give me on doing this, that is: lines/dots, and setting their color(s), along with includes, etc. I'd be very thankful and I'll soon release my program.

Thanks,

ZanM
Oct 26th, 2001, 01:59 PM
#include <wingdi.h>

void Marker(LONG x, LONG y, HWND hwnd)
{
HDC hdc;

hdc = GetDC(hwnd);
MoveToEx(hdc, (int) x - 10, (int) y, (LPPOINT) NULL);
LineTo(hdc, (int) x + 10, (int) y);
MoveToEx(hdc, (int) x, (int) y - 10, (LPPOINT) NULL);
LineTo(hdc, (int) x, (int) y + 10);

ReleaseDC(hwnd, hdc);
}

// Line- and arc-drawing variables

static BOOL bCollectPoints;
static POINT ptMouseDown[32];
static int index;
POINTS ptTmp;
RECT rc;

case WM_LBUTTONDOWN:


if (bCollectPoints && index < 32)
{
// Create the region from the client area.

GetClientRect(hwnd, &rc);
hrgn = CreateRectRgn(rc.left, rc.top,
rc.right, rc.bottom);

ptTmp = MAKEPOINTS((POINTS FAR *) lParam);
ptMouseDown[index].x = (LONG) ptTmp.x;
ptMouseDown[index].y = (LONG) ptTmp.y;

// Test for a hit in the client rectangle.

if (PtInRegion(hrgn, ptMouseDown[index].x,
ptMouseDown[index].y))
{
// If a hit occurs, record the mouse coords.

Marker(ptMouseDown[index].x, ptMouseDown[index].y,
hwnd);
index++;
}
}
break;

come on Dig you should be abble to use msdn :)

LineTo, ArcTo, ellipce, rectangle, and so on .... Platform SDK --> Graphics and Multimedia --> Windows GDI --> Lines and Curves also check out Filled Shapes

DiGiTaIErRoR
Oct 26th, 2001, 09:50 PM
Ok, you obviously don't know just how much of a newbie I am....

If you could... could you make it a VC++ workspace and send me it?

my e-mail has changed since i started my account... if you'd please... send it to fire_bot@hotmail.com

Thanks,

P.S. I have a hard time making a Hello World Console app... :rolleyes: but Ii *should* be able to make the calculations...

sin, cos they work like y = sin(x) * 3; right?

CornedBee
Oct 27th, 2001, 05:59 AM
yeah, and don't include <wingdi.h> but rather <windows.h> or else you get a lot of very confusing errors (all errors in VC++ are confusing, but especially if you are a newbie).
To create a basic API application, do
File->New->Projects->Win32 Application->A "Hello, World!" aplication. This creates a working application for you, so you get an idea of how to create windows and how to draw.