annotate lamertetris/sources/shape.C @ 1:84a8cf4ae913

immposiblerush-0.230919-0.1
author prymula <prymula76@outlook.com>
date Tue, 26 Sep 2023 21:47:56 +0200
parents 2787f5e749ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #include "shape.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
2
prymula <prymula76@outlook.com>
parents:
diff changeset
3 Shape::Shape() {}
prymula <prymula76@outlook.com>
parents:
diff changeset
4
prymula <prymula76@outlook.com>
parents:
diff changeset
5 SDL_Surface * Shape::createBoxMask(int width, int height) {
prymula <prymula76@outlook.com>
parents:
diff changeset
6
prymula <prymula76@outlook.com>
parents:
diff changeset
7 /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
prymula <prymula76@outlook.com>
parents:
diff changeset
8 as expected by OpenGL for textures */
prymula <prymula76@outlook.com>
parents:
diff changeset
9 SDL_Surface *surface;
prymula <prymula76@outlook.com>
parents:
diff changeset
10 Uint32 rmask, gmask, bmask, amask;
prymula <prymula76@outlook.com>
parents:
diff changeset
11 //int width=80;
prymula <prymula76@outlook.com>
parents:
diff changeset
12 //int height=80;
prymula <prymula76@outlook.com>
parents:
diff changeset
13
prymula <prymula76@outlook.com>
parents:
diff changeset
14 /* SDL interprets each pixel as a 32-bit number, so our masks must depend
prymula <prymula76@outlook.com>
parents:
diff changeset
15 on the endianness (byte order) of the machine */
prymula <prymula76@outlook.com>
parents:
diff changeset
16 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
prymula <prymula76@outlook.com>
parents:
diff changeset
17 rmask = 0xff000000;
prymula <prymula76@outlook.com>
parents:
diff changeset
18 gmask = 0x00ff0000;
prymula <prymula76@outlook.com>
parents:
diff changeset
19 bmask = 0x0000ff00;
prymula <prymula76@outlook.com>
parents:
diff changeset
20 amask = 0x000000ff;
prymula <prymula76@outlook.com>
parents:
diff changeset
21 #else
prymula <prymula76@outlook.com>
parents:
diff changeset
22 rmask = 0x000000ff;
prymula <prymula76@outlook.com>
parents:
diff changeset
23 gmask = 0x0000ff00;
prymula <prymula76@outlook.com>
parents:
diff changeset
24 bmask = 0x00ff0000;
prymula <prymula76@outlook.com>
parents:
diff changeset
25 amask = 0xff000000;
prymula <prymula76@outlook.com>
parents:
diff changeset
26 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
27
prymula <prymula76@outlook.com>
parents:
diff changeset
28 surface = SDL_CreateRGBSurface(0, width, height, 32,
prymula <prymula76@outlook.com>
parents:
diff changeset
29 rmask, gmask, bmask, amask);
prymula <prymula76@outlook.com>
parents:
diff changeset
30
prymula <prymula76@outlook.com>
parents:
diff changeset
31 if (surface == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
32 SDL_Log("SDL_CreateRGBSurface() failed: %s", SDL_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
33 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
34 }
prymula <prymula76@outlook.com>
parents:
diff changeset
35
prymula <prymula76@outlook.com>
parents:
diff changeset
36 /* or using the default masks for the depth: */
prymula <prymula76@outlook.com>
parents:
diff changeset
37 //surface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
prymula <prymula76@outlook.com>
parents:
diff changeset
38
prymula <prymula76@outlook.com>
parents:
diff changeset
39
prymula <prymula76@outlook.com>
parents:
diff changeset
40 return surface;
prymula <prymula76@outlook.com>
parents:
diff changeset
41 }
prymula <prymula76@outlook.com>
parents:
diff changeset
42
prymula <prymula76@outlook.com>
parents:
diff changeset
43
prymula <prymula76@outlook.com>
parents:
diff changeset
44 SDL_Surface * Shape::createField(int w,int h, int r, int g, int b){
prymula <prymula76@outlook.com>
parents:
diff changeset
45
prymula <prymula76@outlook.com>
parents:
diff changeset
46 SDL_Surface *s;
prymula <prymula76@outlook.com>
parents:
diff changeset
47 //s=Szlam::createBoxMask(w,h);
prymula <prymula76@outlook.com>
parents:
diff changeset
48 s=Shape::createBoxMask(w,h);
prymula <prymula76@outlook.com>
parents:
diff changeset
49 SDL_FillRect(s, NULL, SDL_MapRGB(s->format, r, g, b));
prymula <prymula76@outlook.com>
parents:
diff changeset
50 return s;
prymula <prymula76@outlook.com>
parents:
diff changeset
51 }
prymula <prymula76@outlook.com>
parents:
diff changeset
52
prymula <prymula76@outlook.com>
parents:
diff changeset
53 void Shape::setColor(int color, int *r, int *g, int*b){
prymula <prymula76@outlook.com>
parents:
diff changeset
54
prymula <prymula76@outlook.com>
parents:
diff changeset
55 switch(color){
prymula <prymula76@outlook.com>
parents:
diff changeset
56 case 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
57 *r=255, *g=255, *b=255;
prymula <prymula76@outlook.com>
parents:
diff changeset
58 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
59 case 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
60 *r=255, *g=0, *b=0; //czerwony
prymula <prymula76@outlook.com>
parents:
diff changeset
61 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
62 case 2:
prymula <prymula76@outlook.com>
parents:
diff changeset
63 *r=0, *g=255, *b=0; //zielony
prymula <prymula76@outlook.com>
parents:
diff changeset
64 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
65 case 3:
prymula <prymula76@outlook.com>
parents:
diff changeset
66 *r=0, *g=0, *b=255; //niebieski
prymula <prymula76@outlook.com>
parents:
diff changeset
67 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
68 case 4:
prymula <prymula76@outlook.com>
parents:
diff changeset
69 *r=0, *g=255, *b=255; //seledynowy
prymula <prymula76@outlook.com>
parents:
diff changeset
70 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
71 case 5:
prymula <prymula76@outlook.com>
parents:
diff changeset
72 *r=255, *g=255, *b=0; //żółty
prymula <prymula76@outlook.com>
parents:
diff changeset
73 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
74 case 6:
prymula <prymula76@outlook.com>
parents:
diff changeset
75 *r=170, *g=0, *b=255; //fiolet
prymula <prymula76@outlook.com>
parents:
diff changeset
76 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
77 case 7:
prymula <prymula76@outlook.com>
parents:
diff changeset
78 *r=113, *g=255, *b=0; //fiolet
prymula <prymula76@outlook.com>
parents:
diff changeset
79 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
80
prymula <prymula76@outlook.com>
parents:
diff changeset
81 }
prymula <prymula76@outlook.com>
parents:
diff changeset
82 }