Re: windows graphics engine
- Posted by mic _ <stabmaster_ at HOTMAIL.COM> Dec 20, 2000
- 612 views
>Where do I get Windows GDI? The GDI (Graphics Device Interface (?) ) is a standard component of Windows. You can import the routines from gdi32.dll. Here's an example of how to use the gdi function StretchDIBits() (note that StretchDIBits isn't the fastest function available). (note 2: this code is for 8-bit bitmaps) --STRUCT BITMAPINFOHEADER global constant biSize = 0, biWidth = 4, biHeight = 8, biPlanes = 12, biBitCount = 14, biCompression = 16, biSizeImage = 20, biXPelsPerMeter = 24, biYPelsPerMeter = 28, biClrUsed = 32, biClrImportant = 36, SIZE_OF_BITMAPINFOHEADER = 40 --END STRUCT --STRUCT RGBQUAD global constant rgbBlue = 0, rgbGreen = 1, rgbRed = 2, rgbReserved = 3, SIZE_OF_RGBQUAD = 4 --END STRUCT --### STRUCT RECT ### global constant rect_left = 0, rect_top = 4, rect_right = 8, rect_bottom = 12, SIZE_OF_RECT = 16 --### END STRUCT ### --### Color component compression ### global constant BI_RGB = 0, BI_RLE8 = 1, BI_RLE4 = 2, BI_BITFIELDS = 3 global constant DIB_PAL_COLORS = 1, DIB_RGB_COLORS = 0 --### Raster operations ### global constant SRCINVERT = #660046, SRCAND = #8800C6, MERGEPAINT = #BB0226, MERGECOPY = #C000CA, SRCCOPY = #CC0020, SRCPAINT = #EE0086 --STRUCT BITMAPINFO global constant BITMAPINFOHEADER = 0, RGBQUAD = 40, SIZE_OF_BITMAPINFO = SIZE_OF_BITMAPINFOHEADER + SIZE_OF_RGBQUAD --END STRUCT -- make room for one BITMAPINFOHEADER + 256 RGBQUAD structs bi = allocate(SIZE_OF_BITMAPINFOHEADER + 1024) constant rect = allocate(SIZE_OF_RECT) constant Width = ???, Height = ???, Pointer = allocate(Width*Height) -- 'Pointer' is your bitmap, this is where you keep your graphics. atom dc --### Here's how to set the palette ### --### R, G & B should be 0-255 ### procedure set_windows_palette(sequence pal) for i=0 to 255 do poke(bi + RGBQUAD + (i*4),pal[i+1][3]) poke(bi + RGBQUAD + (i*4)+1,pal[i+1][2]) poke(bi + RGBQUAD + (i*4)+2,pal[i+1][1]) poke(bi + RGBQUAD + (i*4)+3,0) end for end procedure --### Do this once at init ### mem_set(bi, 0, SIZE_OF_BITMAPINFOHEADER) --### Do this whenever you repaint your window ### poke4(bi + BITMAPINFOHEADER + biSize, SIZE_OF_BITMAPINFOHEADER) poke4(bi + BITMAPINFOHEADER + biWidth, Width) poke4(bi + BITMAPINFOHEADER + biHeight, Height) poke_word(bi + BITMAPINFOHEADER + biPlanes, 1) poke_word(bi + BITMAPINFOHEADER + biBitCount, 8) -- the RGBQUAD entries contains explicit RGB values (actually BGRX..) poke4(bi + BITMAPINFOHEADER + biCompression, BI_RGB) dc = GetDC(hwnd) if GetClientRect(hwnd,rect) then end if -- this is it - StretchDIBits copies a memory block to a window's device context -- syntax is as follows: -- StretchDIBits({ -- atom hdc, handle of device context -- atom XDest, x-coordinate of upper-left corner of dest. rect. -- atom YDest, y-coordinate of upper-left corner of dest. rect. -- atom nDestWidth, width of destination rectangle -- atom nDestHeight, height of destination rectangle -- atom XSrc, x-coordinate of upper-left corner of source rect. -- atom YSrc, y-coordinate of upper-left corner of source rect. -- atom nSrcWidth, width of source rectangle -- atom nSrcHeight, height of source rectangle -- atom lpBits, address of bitmap bits -- atom lpBitsInfo, address of bitmap data -- atom iUsage, usage -- atom dwRop raster operation code -- }) StretchDIBits({dc,0,0,peek4s(rect + rect_right),peek4s(rect + rect_bottom), 0,0,Width,Height,Pointer,bi,DIB_RGB_COLORS,SRCCOPY}) if ReleaseDC(hwnd,dc) then end if --### The End ### If this just confused you, I've written some programs that actually use this stuff, and not only for 8-bit graphics. Try searching for "windows animation" at the Euphoria site and my program should pop up at the top.. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.