Subversion Repositories Kolibri OS

Rev

Rev 8200 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8200 Rev 8202
Line 1... Line -...
1
/* Instructions to compile this file with newlib (Assuming you have set up environment
-
 
-
 
1
/*
Line 2... Line 2...
2
 
2
 
3
kos32-gcc -c -I/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/include -I/home/bob/kolibrios/contrib/sdk/sources/libpng/ -I/home/bob/kolibrios/contrib/sdk/sources/zlib -I/home/bob/kolibrios/contrib/sdk/sources/freetype/include -I/home/bob/kolibrios/contrib/sdk/sources/freetype/include -I/home/bob/kolibrios/contrib/sdk/sources/SDL-1.2.2/include/ -std=c99 -D_KOLIBRIOS -Dnskolibrios -g   -Wundef   -U_Win32 -U_WIN32 -U__MINGW32__ SDLTest.c
-
 
4
 
-
 
5
  kos32-ld SDLTest.o -T/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/app.lds -nostdlib -static --image-base 0 -lgcc -L/home/autobuild/tools/win32/mingw32/lib /home/autobuild/tools/win32/lib/libdll.a /home/autobuild/tools/win32/lib/libapp.a /home/autobuild/tools/win32/lib/libSDL.a /home/autobuild/tools/win32/lib/libc.dll.a -static -o sdltest
-
 
6
 
-
 
7
objcopy -O binary sdltest
-
 
8
 
-
 
9
Now sdltest is your binary to run on Kolibri for SDL Demo.
-
 
10
 
-
 
11
-- ashmew2
-
 
12
 
-
 
13
You can found Makefile
3
Makefile in this folder
14
-- maxcodehack
4
-- maxcodehack
Line 15... Line -...
15
*/
-
 
16
 
-
 
17
#include 
-
 
18
#include 
-
 
19
 
-
 
20
#define WIDTH 640
-
 
21
#define HEIGHT 480
-
 
22
#define BPP 4
-
 
23
#define DEPTH 32
5
*/
24
 
-
 
25
void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
-
 
26
{
-
 
Line -... Line 6...
-
 
6
 
-
 
7
/* Simple program:  Test bitmap blits */
27
    Uint32 *pixmem32;
8
 
Line 28... Line 9...
28
    Uint32 colour;  
9
#include 
29
 
10
#include 
30
    colour = SDL_MapRGB( screen->format, r, g, b );
-
 
Line -... Line 11...
-
 
11
#include 
-
 
12
 
Line 31... Line 13...
31
  
13
// We can use Newlib functions with Menuetlibc library SDL!
32
    pixmem32 = (Uint32*) screen->pixels  + y + x;
14
#include 
-
 
15
 
33
    *pixmem32 = colour;
16
#include "SDL.h"
Line 34... Line 17...
34
}
17
#include "picture.xbm"
-
 
18
 
35
 
19
SDL_Surface *LoadXBM(SDL_Surface *screen, int w, int h, Uint8 *bits)
36
 
20
{
-
 
21
	SDL_Surface *bitmap;
-
 
22
	Uint8 *line;
37
void DrawScreen(SDL_Surface* screen, int h)
23
 
Line -... Line 24...
-
 
24
	/* Allocate the bitmap */
38
{ 
25
	bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0);
-
 
26
	if ( bitmap == NULL ) {
39
    int x, y, ytimesw;
27
		fprintf(stderr, "Couldn't allocate bitmap: %s\n",
-
 
28
						SDL_GetError());
-
 
29
		return(NULL);
40
  
30
	}
41
    if(SDL_MUSTLOCK(screen)) 
31
 
-
 
32
	/* Copy the pixels */
42
    {
33
	line = (Uint8 *)bitmap->pixels;
-
 
34
	w = (w+7)/8;
43
        if(SDL_LockSurface(screen) < 0) return;
35
	while ( h-- ) {
-
 
36
		memcpy(line, bits, w);
44
    }
37
		/* X11 Bitmap images have the bits reversed */
45
 
38
		{ int i, j; Uint8 *buf, byte;
46
    for(y = 0; y < screen->h; y++ ) 
-
 
47
    {
-
 
48
        ytimesw = y*screen->pitch/BPP;
-
 
49
        for( x = 0; x < screen->w; x++ ) 
39
			for ( buf=line, i=0; i
-
 
40
				byte = *buf;
-
 
41
				*buf = 0;
-
 
42
				for ( j=7; j>=0; --j ) {
-
 
43
					*buf |= (byte&0x01)<
50
        {
44
					byte >>= 1;
Line 51... Line 45...
51
            setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
45
				}
52
        }
46
			}
53
    }
47
		}
-
 
48
		line += bitmap->pitch;
-
 
49
		bits += w;
-
 
50
	}
-
 
51
	return(bitmap);
-
 
52
}
54
    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
53
 
Line -... Line 54...
-
 
54
int main(int argc, char *argv[])
-
 
55
{
-
 
56
	SDL_Surface *screen;
-
 
57
	SDL_Surface *bitmap;
-
 
58
	Uint8  video_bpp;
-
 
59
	Uint32 videoflags;
-
 
60
	Uint8 *buffer;
55
  
61
	int i, done;
-
 
62
	SDL_Event event;
-
 
63
 
-
 
64
	/* Initialize SDL */
-
 
65
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
-
 
66
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
56
    SDL_Flip(screen); 
67
		exit(1);
-
 
68
	}
57
}
69
	atexit(SDL_Quit);
-
 
70
 
58
 
71
	video_bpp = 0;
-
 
72
	videoflags = SDL_SWSURFACE;
-
 
73
	/* Set 640x480 video mode */
-
 
74
	if ( (screen=SDL_SetVideoMode(640,480,video_bpp,videoflags)) == NULL ) {
-
 
75
		fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
-
 
76
						video_bpp, SDL_GetError());
-
 
77
		exit(2);
-
 
78
	}
-
 
79
 
-
 
80
	/* Set the surface pixels and refresh! */
-
 
81
	if ( SDL_LockSurface(screen) < 0 ) {
-
 
82
		fprintf(stderr, "Couldn't lock the display surface: %s\n",
59
 
83
							SDL_GetError());
-
 
84
		exit(2);
60
int main(int argc, char* argv[])
85
	}
-
 
86
	buffer=(Uint8 *)screen->pixels;
-
 
87
	for ( i=0; ih; ++i ) {
-
 
88
		memset(buffer,(i*255)/screen->h, screen->pitch);
-
 
89
		buffer += screen->pitch;
-
 
90
	}
-
 
91
	SDL_UnlockSurface(screen);
61
{
92
	SDL_UpdateRect(screen, 0, 0, 0, 0);
-
 
93
 
-
 
94
	/* Load the bitmap */
-
 
95
	bitmap = LoadXBM(screen, picture_width, picture_height,
-
 
96
					(Uint8 *)picture_bits);
-
 
97
	if ( bitmap == NULL ) {
62
    SDL_Surface *screen;
98
		exit(1);
-
 
99
	}
-
 
100
 
-
 
101
	/* Wait for a keystroke */
-
 
102
	done = 0;
63
    SDL_Event event;
103
	while ( !done ) {
-
 
104
		/* Check for events */
-
 
105
		while ( SDL_PollEvent(&event) ) {
-
 
106
			switch (event.type) {
64
  
107
				case SDL_MOUSEBUTTONDOWN: {
65
    int keypress = 0;
-
 
66
    int h=0; 
-
 
67
  
-
 
68
    if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
-
 
69
   
-
 
70
    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE)))
-
 
71
    {
-
 
72
        SDL_Quit();
-
 
73
        return 1;
-
 
74
    }
-
 
75
  
108
					SDL_Rect dst;
76
    while(!keypress) 
109
 
77
    {
110
					dst.x = event.button.x - bitmap->w/2;
-
 
111
					dst.y = event.button.y - bitmap->h/2;
-
 
112
					dst.w = bitmap->w;
-
 
113
					dst.h = bitmap->h;
-
 
114
					SDL_BlitSurface(bitmap, NULL,
-
 
115
								screen, &dst);
-
 
116
					SDL_UpdateRects(screen,1,&dst);
78
         DrawScreen(screen,h++);
117
					}
79
         while(SDL_PollEvent(&event)) 
118
					break;
-
 
119
				case SDL_KEYDOWN:
-
 
120
					/* Any key press quits the app... */
-
 
121
					done = 1;
-
 
122
					break;
80
         {      
123
				case SDL_QUIT:
81
              switch (event.type) 
124
					done = 1;
82
              {
-
 
-
 
125
					break;
83
                  case SDL_QUIT:
126
				default:
84
	              keypress = 1;
-
 
85
	              break;
127
					break;
86
                  case SDL_KEYDOWN:
128
			}