-
Plotting a pixel.
Hi, i am writing a relativley simple game and i am hoping to expand soon into graphics, i will be posting the source shortly (once i get back from school - lol) but was wondering if anyone could provide some code to plot a single pixel on the screen as i have trawled countless websites and tutorials to no avail. :confused:
-
Well, you need to be specific about which OS and compiler you'll be using, then perhaps we can advise you on choosing a graphical API to go along with it.
-
Hokay, soz about that - bloodshed dev c++ - win 98 se , (i also run red hat 7.2 but 98 is the os i code on)
-
Check out these tutorials...
Here
Though this was probably better to be posted in the Windows programming forum on cboard, but check the tutorials first...
-
Thanks anyway but ive found a tutorial that suits me just fine - thanks again for the help. i shall return if more is needed :)
-
Although I am having some windows compiler issues right now.. here is some code which I think will compile and run.
Code:
#include<windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "Pixel Fun";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("Pixel Fun","Window",WS_OVERLAPPEDWINDOW,0,0,600,460,NULL,NULL,hInstance,NULL);
UpdateWindow(hWindow);
MSG Message;
while(GetMessage(&Message,NULL,0,0))
DispatchMessage(&Message);
return(Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
static BYTE Pixel[6][5] = {0,255,0,255,0,0,
255,0,255,0,255,0,
0,255,0,255,0,0,
255,0,255,0,255,0,
0,255,0,255,0,0 };
static HBITMAP hBitmap;
static HDC hdcmem;
switch(uiMessage)
{
case WM_LBUTTONDOWN:
HDC hdc;
hdc = GetDC(hWnd);
hdcmem = CreateCompatibleDC(hdc);
hBitmap = CreateBitmap(6,5,1,8,Pixel);
SelectObject(hdcmem, hBitmap);
RECT rect;
GetClientRect(hWnd, &rect);
int x,y;
for(y=0;y<rect.bottom;y+=5)
for(x=0;x<rect.right;x+=5)
BitBlt(hdc,x,y,5,5,hdcmem,0,0,SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hdcmem);
ReleaseDC(hWnd, hdc);
return 0;
case WM_RBUTTONDOWN:
hdc = GetDC(hWnd);
hdcmem = CreateCompatibleDC(hdc);
hBitmap = CreateBitmap(5,5,1,8,Pixel);
SelectObject(hdcmem, hBitmap);
GetClientRect(hWnd, &rect);
for(y=0;y<rect.bottom;y+=10)
for(x=0;x<rect.right;x+=10)
StretchBlt(hdc,x,y,10,10,hdcmem,0,0,5,5,SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hdcmem);
ReleaseDC(hWnd, hdc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, uiMessage, wParam, lParam);
}
}