Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
6cc1b97f
Commit
6cc1b97f
authored
Jul 23, 2010
by
Eli Gottlieb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on color-key mode.
parent
abb4ad73
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
25 deletions
+39
-25
SDL_shape.c
src/video/SDL_shape.c
+1
-1
testshape.c
test/testshape.c
+38
-24
No files found.
src/video/SDL_shape.c
View file @
6cc1b97f
...
@@ -96,7 +96,7 @@ void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8*
...
@@ -96,7 +96,7 @@ void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8*
break
;
break
;
case
(
ShapeModeColorKey
):
case
(
ShapeModeColorKey
):
key
=
mode
.
parameters
.
colorKey
;
key
=
mode
.
parameters
.
colorKey
;
bitmap
[
bitmap_pixel
/
ppb
]
|=
(
key
.
r
==
r
&&
key
.
g
==
g
&&
key
.
b
==
b
?
value
:
0
)
<<
((
ppb
-
1
)
-
(
bitmap_pixel
%
ppb
));
bitmap
[
bitmap_pixel
/
ppb
]
|=
(
(
key
.
r
==
r
&&
key
.
g
==
g
&&
key
.
b
==
b
)
?
value
:
0
)
<<
((
ppb
-
1
)
-
(
bitmap_pixel
%
ppb
));
break
;
break
;
}
}
}
}
...
...
test/testshape.c
View file @
6cc1b97f
...
@@ -14,6 +14,12 @@
...
@@ -14,6 +14,12 @@
#define TICK_INTERVAL 18
#define TICK_INTERVAL 18
typedef
struct
LoadedPicture
{
SDL_Surface
*
surface
;
SDL_Texture
*
texture
;
SDL_WindowShapeMode
mode
;
}
LoadedPicture
;
void
render
(
SDL_Window
*
window
,
SDL_Texture
*
texture
,
SDL_Rect
texture_dimensions
)
{
void
render
(
SDL_Window
*
window
,
SDL_Texture
*
texture
,
SDL_Rect
texture_dimensions
)
{
SDL_SelectRenderer
(
window
);
SDL_SelectRenderer
(
window
);
...
@@ -49,28 +55,39 @@ int main(int argc,char** argv) {
...
@@ -49,28 +55,39 @@ int main(int argc,char** argv) {
}
}
Uint8
num_pictures
=
argc
-
1
;
Uint8
num_pictures
=
argc
-
1
;
SDL_Surface
**
pictures
=
malloc
(
sizeof
(
SDL_Surface
*
)
*
num_pictures
);
LoadedPicture
*
pictures
=
malloc
(
sizeof
(
LoadedPicture
)
*
num_pictures
);
int
i
=
0
;
int
i
=
0
;
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
pictures
[
i
]
=
NULL
;
pictures
[
i
]
.
surface
=
NULL
;
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
{
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
{
pictures
[
i
]
=
SDL_LoadBMP
(
argv
[
i
+
1
]);
pictures
[
i
]
.
surface
=
SDL_LoadBMP
(
argv
[
i
+
1
]);
if
(
pictures
[
i
]
==
NULL
)
{
if
(
pictures
[
i
]
.
surface
==
NULL
)
{
int
j
=
0
;
int
j
=
0
;
for
(
j
=
0
;
j
<
num_pictures
;
j
++
)
for
(
j
=
0
;
j
<
num_pictures
;
j
++
)
if
(
pictures
[
j
]
!=
NULL
)
if
(
pictures
[
j
]
.
surface
!=
NULL
)
SDL_FreeSurface
(
pictures
[
j
]);
SDL_FreeSurface
(
pictures
[
j
]
.
surface
);
free
(
pictures
);
free
(
pictures
);
SDL_VideoQuit
();
SDL_VideoQuit
();
printf
(
"Could not load surface from named bitmap file.
\n
"
);
printf
(
"Could not load surface from named bitmap file.
\n
"
);
exit
(
-
3
);
exit
(
-
3
);
}
}
SDL_PixelFormat
*
format
=
pictures
[
i
].
surface
->
format
;
Uint32
format_enum
=
SDL_MasksToPixelFormatEnum
(
format
->
BitsPerPixel
,
format
->
Rmask
,
format
->
Gmask
,
format
->
Bmask
,
format
->
Amask
);
if
(
SDL_ISPIXELFORMAT_ALPHA
(
format_enum
))
{
pictures
[
i
].
mode
.
mode
=
ShapeModeBinarizeAlpha
;
pictures
[
i
].
mode
.
parameters
.
binarizationCutoff
=
1
;
}
else
{
pictures
[
i
].
mode
.
mode
=
ShapeModeColorKey
;
SDL_Color
black
=
{
0
,
0
,
0
,
0xff
};
pictures
[
i
].
mode
.
parameters
.
colorKey
=
black
;
}
}
}
SDL_Window
*
window
=
SDL_CreateShapedWindow
(
"SDL_Shape test"
,
SHAPED_WINDOW_X
,
SHAPED_WINDOW_Y
,
SHAPED_WINDOW_DIMENSION
,
SHAPED_WINDOW_DIMENSION
,
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_SHOWN
);
SDL_Window
*
window
=
SDL_CreateShapedWindow
(
"SDL_Shape test"
,
SHAPED_WINDOW_X
,
SHAPED_WINDOW_Y
,
SHAPED_WINDOW_DIMENSION
,
SHAPED_WINDOW_DIMENSION
,
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_SHOWN
);
if
(
window
==
NULL
)
{
if
(
window
==
NULL
)
{
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
SDL_FreeSurface
(
pictures
[
i
]);
SDL_FreeSurface
(
pictures
[
i
]
.
surface
);
free
(
pictures
);
free
(
pictures
);
SDL_VideoQuit
();
SDL_VideoQuit
();
printf
(
"Could not create shaped window for SDL_Shape.
\n
"
);
printf
(
"Could not create shaped window for SDL_Shape.
\n
"
);
...
@@ -79,26 +96,24 @@ int main(int argc,char** argv) {
...
@@ -79,26 +96,24 @@ int main(int argc,char** argv) {
if
(
SDL_CreateRenderer
(
window
,
-
1
,
SDL_RENDERER_PRESENTFLIP2
)
==
-
1
)
{
if
(
SDL_CreateRenderer
(
window
,
-
1
,
SDL_RENDERER_PRESENTFLIP2
)
==
-
1
)
{
SDL_DestroyWindow
(
window
);
SDL_DestroyWindow
(
window
);
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
SDL_FreeSurface
(
pictures
[
i
]);
SDL_FreeSurface
(
pictures
[
i
]
.
surface
);
free
(
pictures
);
free
(
pictures
);
SDL_VideoQuit
();
SDL_VideoQuit
();
printf
(
"Could not create rendering context for SDL_Shape window.
\n
"
);
printf
(
"Could not create rendering context for SDL_Shape window.
\n
"
);
exit
(
-
5
);
exit
(
-
5
);
}
}
SDL_Texture
**
textures
=
malloc
(
sizeof
(
SDL_Texture
*
)
*
num_pictures
);
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
textures
[
i
]
=
NULL
;
pictures
[
i
].
texture
=
NULL
;
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
{
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
{
textures
[
i
]
=
SDL_CreateTextureFromSurface
(
0
,
pictures
[
i
]
);
pictures
[
i
].
texture
=
SDL_CreateTextureFromSurface
(
0
,
pictures
[
i
].
surface
);
if
(
textures
[
i
]
==
NULL
)
{
if
(
pictures
[
i
].
texture
==
NULL
)
{
int
j
=
0
;
int
j
=
0
;
for
(
j
=
0
;
j
<
num_pictures
;
i
++
)
for
(
j
=
0
;
j
<
num_pictures
;
i
++
)
if
(
textures
[
i
]
!=
NULL
)
if
(
pictures
[
i
].
texture
!=
NULL
)
SDL_DestroyTexture
(
textures
[
i
]);
SDL_DestroyTexture
(
pictures
[
i
].
texture
);
free
(
textures
);
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
SDL_FreeSurface
(
pictures
[
i
]);
SDL_FreeSurface
(
pictures
[
i
]
.
surface
);
free
(
pictures
);
free
(
pictures
);
SDL_DestroyRenderer
(
window
);
SDL_DestroyRenderer
(
window
);
SDL_DestroyWindow
(
window
);
SDL_DestroyWindow
(
window
);
...
@@ -116,9 +131,9 @@ int main(int argc,char** argv) {
...
@@ -116,9 +131,9 @@ int main(int argc,char** argv) {
int
button_down
=
0
;
int
button_down
=
0
;
Uint32
format
=
0
,
access
=
0
;
Uint32
format
=
0
,
access
=
0
;
SDL_Rect
texture_dimensions
=
{
0
,
0
,
0
,
0
};
SDL_Rect
texture_dimensions
=
{
0
,
0
,
0
,
0
};
SDL_QueryTexture
(
textures
[
current_picture
]
,
&
format
,
&
access
,
&
texture_dimensions
.
w
,
&
texture_dimensions
.
h
);
SDL_QueryTexture
(
pictures
[
current_picture
].
texture
,
&
format
,
&
access
,
&
texture_dimensions
.
w
,
&
texture_dimensions
.
h
);
SDL_SetWindowSize
(
window
,
texture_dimensions
.
w
,
texture_dimensions
.
h
);
SDL_SetWindowSize
(
window
,
texture_dimensions
.
w
,
texture_dimensions
.
h
);
SDL_SetWindowShape
(
window
,
pictures
[
current_picture
],
&
mode
);
SDL_SetWindowShape
(
window
,
pictures
[
current_picture
]
.
surface
,
&
mode
);
next_time
=
SDL_GetTicks
()
+
TICK_INTERVAL
;
next_time
=
SDL_GetTicks
()
+
TICK_INTERVAL
;
while
(
should_exit
==
0
)
{
while
(
should_exit
==
0
)
{
event_pending
=
SDL_PollEvent
(
&
event
);
event_pending
=
SDL_PollEvent
(
&
event
);
...
@@ -133,28 +148,27 @@ int main(int argc,char** argv) {
...
@@ -133,28 +148,27 @@ int main(int argc,char** argv) {
current_picture
+=
1
;
current_picture
+=
1
;
if
(
current_picture
>=
num_pictures
)
if
(
current_picture
>=
num_pictures
)
current_picture
=
0
;
current_picture
=
0
;
SDL_QueryTexture
(
textures
[
current_picture
]
,
&
format
,
&
access
,
&
texture_dimensions
.
w
,
&
texture_dimensions
.
h
);
SDL_QueryTexture
(
pictures
[
current_picture
].
texture
,
&
format
,
&
access
,
&
texture_dimensions
.
w
,
&
texture_dimensions
.
h
);
SDL_SetWindowSize
(
window
,
texture_dimensions
.
w
,
texture_dimensions
.
h
);
SDL_SetWindowSize
(
window
,
texture_dimensions
.
w
,
texture_dimensions
.
h
);
SDL_SetWindowShape
(
window
,
pictures
[
current_picture
],
&
mode
);
SDL_SetWindowShape
(
window
,
pictures
[
current_picture
]
.
surface
,
&
mode
);
}
}
if
(
event
.
type
==
SDL_QUIT
)
if
(
event
.
type
==
SDL_QUIT
)
should_exit
=
1
;
should_exit
=
1
;
event_pending
=
0
;
event_pending
=
0
;
}
}
render
(
window
,
textures
[
current_picture
]
,
texture_dimensions
);
render
(
window
,
pictures
[
current_picture
].
texture
,
texture_dimensions
);
SDL_Delay
(
time_left
());
SDL_Delay
(
time_left
());
next_time
+=
TICK_INTERVAL
;
next_time
+=
TICK_INTERVAL
;
}
}
//Free the textures.
//Free the textures.
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
SDL_DestroyTexture
(
textures
[
i
]);
SDL_DestroyTexture
(
pictures
[
i
].
texture
);
free
(
textures
);
//Destroy the window.
//Destroy the window.
SDL_DestroyWindow
(
window
);
SDL_DestroyWindow
(
window
);
//Free the original surfaces backing the textures.
//Free the original surfaces backing the textures.
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
for
(
i
=
0
;
i
<
num_pictures
;
i
++
)
SDL_FreeSurface
(
pictures
[
i
]);
SDL_FreeSurface
(
pictures
[
i
]
.
surface
);
free
(
pictures
);
free
(
pictures
);
//Call SDL_VideoQuit() before quitting.
//Call SDL_VideoQuit() before quitting.
SDL_VideoQuit
();
SDL_VideoQuit
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment