2 * This source was ocassionally found by Google here:
3 * http://megaburken.net/~patrik/
5 * The code is unmodified (except fixed #include file names in order to compile
8 * I hope the original author is not against spreading it, especially taking
9 * into account its experimental nature.
10 * Pavel Fedin <pavel_fedin@mail.ru>
16 #include <exec/exec.h>
17 #include <graphics/gfxbase.h>
18 #include <cybergraphx/cybergraphics.h>
19 #include <intuition/intuition.h>
21 #include <proto/exec.h>
22 #include <proto/graphics.h>
23 #include <proto/intuition.h>
25 #include <proto/cybergraphics.h>
32 struct GfxBase
*GfxBase
;
33 struct Library
*CyberGfxBase
;
34 struct IntuitionBase
*IntuitionBase
;
36 int main(int argc
, char *argv
[])
38 struct Screen
*myScreen
;
39 struct Window
*myWindow
;
40 struct RastPort myRastPort
;
41 struct BitMap
*myBitMap
;
59 volatile ULONG
*bm_curraddress
;
69 width
= atoi(argv
[1]);
70 height
= atoi(argv
[2]);
71 depth
= atoi(argv
[3]);
75 printf("Wrong number of arguments!\n\n");
76 printf("Usage: CGXTest width height depth\n\n");
81 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39L);
84 printf("Couldnt open graphics.library 40.\n");
87 CyberGfxBase
= OpenLibrary("cybergraphics.library", 41L);
90 printf("Couldnt open cybergraphics.library 41.\n");
91 CloseLibrary((struct Library
*)GfxBase
);
94 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39L);
97 printf("Couldnt open intuition.library 39.\n");
98 CloseLibrary(CyberGfxBase
);
99 CloseLibrary((struct Library
*)GfxBase
);
103 myScreen
= LockPubScreen(NULL
);
106 UnlockPubScreen(NULL
, myScreen
);
110 printf("Couldnt get screen data.\n");
111 CloseLibrary((struct Library
*)IntuitionBase
);
112 CloseLibrary(CyberGfxBase
);
113 CloseLibrary((struct Library
*)GfxBase
);
118 myBitMap
= AllocBitMap(width
, height
, depth
, BMF_MINPLANES
| BMF_DISPLAYABLE
, myScreen
->RastPort
.BitMap
);
121 printf("Couldnt allocate bitmap.\n");
122 CloseLibrary(CyberGfxBase
);
123 CloseLibrary((struct Library
*)GfxBase
);
124 CloseLibrary((struct Library
*)IntuitionBase
);
128 //Creates the RastPort used for blitting
129 InitRastPort(&myRastPort
);
130 myRastPort
.BitMap
= myBitMap
;
132 myWindow
= OpenWindowTags(NULL
, //WA_Left, 100,
134 WA_InnerWidth
, width
,
135 WA_InnerHeight
, height
,
136 WA_ScreenTitle
, "Watch out for that trashing! ;)",
140 printf("Couldnt open a new window.\n");
141 FreeBitMap(myBitMap
);
143 CloseLibrary((struct Library
*)IntuitionBase
);
144 CloseLibrary(CyberGfxBase
);
145 CloseLibrary((struct Library
*)GfxBase
);
150 printf("Allocated BitMap data:\n");
152 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_ISCYBERGFX
);
154 printf("It is a CyberGraphX bitmap!\n");
156 printf("It is not a CyberGraphX bitmap!\n");
158 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_ISLINEARMEM
);
160 printf("It supports linear memory access!\n");
162 printf("It does not support linear memory access!\n");
164 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_WIDTH
);
165 printf("Width: %d\n", (int)result
);
167 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_HEIGHT
);
168 printf("Height: %d\n", (int)result
);
170 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_DEPTH
);
171 printf("Depth: %d\n", (int)result
);
173 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_PIXFMT
);
174 printf("Pixel format: ");
224 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_BPPIX
);
225 printf("Bytes per pixel: %d\n", (int)result
);
227 result
=GetCyberMapAttr(myBitMap
, CYBRMATTR_XMOD
);
228 printf("Bytes per row: %d\n\n", (int)result
);
230 printf("Locking BitMap and writing to it...");
231 bitMapHandle
= LockBitMapTags(myBitMap
,
232 LBMI_WIDTH
, &bm_width
,
233 LBMI_HEIGHT
, &bm_height
,
234 LBMI_DEPTH
, &bm_depth
,
235 LBMI_PIXFMT
, &bm_pixfmt
,
236 LBMI_BYTESPERPIX
, &bm_bytesperpix
,
237 LBMI_BYTESPERROW
, &bm_bytesperrow
,
238 LBMI_BASEADDRESS
, &bm_baseaddress
,
244 bm_endaddress
= bm_baseaddress
+ bm_bytesperrow
* bm_height
;
245 for(bm_curraddress
= (ULONG
*)bm_baseaddress
; bm_curraddress
< (ULONG
*)bm_endaddress
; bm_curraddress
++)
246 *bm_curraddress
= 0x102B5FF1;
248 UnLockBitMap(bitMapHandle
);
250 printf("...done.\n\n");
253 printf("Locked BitMap data:\n");
254 printf("Base address: %p\n", (APTR
)bm_baseaddress
);
255 printf("Width: %d\n", (int)bm_width
);
256 printf("Height: %d\n", (int)bm_height
);
257 printf("Depth: %d\n", (int)bm_depth
);
258 printf("Pixel format: ");
307 printf("Bytes per pixel: %d\n", (int)bm_bytesperpix
);
308 printf("Bytes per row: %d\n", (int)bm_bytesperrow
);
311 printf("Blitting BitMap to window...");
312 ClipBlit(&myRastPort
, 0, 0, myWindow
->RPort
, myWindow
->BorderLeft
, myWindow
->BorderTop
, bm_width
, bm_height
, 0xC0);
313 printf("...done.\n");
316 printf("failed, couldnt lock bitmap.\n");
318 printf("\nPress enter to close the window.");
319 result
= (ULONG
)getchar();
321 CloseWindow(myWindow
);
323 FreeBitMap(myBitMap
);
325 CloseLibrary((struct Library
*)IntuitionBase
);
326 CloseLibrary(CyberGfxBase
);
327 CloseLibrary((struct Library
*)GfxBase
);
329 printf("\nExiting.\n");