annotate test/testshape.c @ 5032:6ccfbaef0c0a

Removed extra space
author Sam Lantinga <slouken@libsdl.org>
date Wed, 19 Jan 2011 11:35:31 -0800
parents 579dabb141ea
children dc0dfdd58f27
rev   line source
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
1 #include <stdlib.h>
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
2 #include <math.h>
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
3 #include <stdio.h>
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
4 #include "SDL.h"
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
5 #include "SDL_shape.h"
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
6
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
7 #define SHAPED_WINDOW_X 150
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
8 #define SHAPED_WINDOW_Y 150
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
9 #define SHAPED_WINDOW_DIMENSION 640
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
10
4849
0b918c186938 Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
egottlieb
parents: 4837
diff changeset
11 #define TICK_INTERVAL 1000/10
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
12
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
13 typedef struct LoadedPicture {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
14 SDL_Surface *surface;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
15 SDL_Texture *texture;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
16 SDL_WindowShapeMode mode;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
17 } LoadedPicture;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
18
4804
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
19 void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) {
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
20 SDL_SelectRenderer(window);
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
21
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
22 //Clear render-target to blue.
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
23 SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff);
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
24 SDL_RenderClear();
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
25
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
26 //Render the texture.
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
27 SDL_RenderCopy(texture,&texture_dimensions,&texture_dimensions);
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
28
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
29 SDL_RenderPresent();
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
30 }
b33752266d8f Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4803
diff changeset
31
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
32 static Uint32 next_time;
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
33
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
34 Uint32 time_left() {
4849
0b918c186938 Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
egottlieb
parents: 4837
diff changeset
35 Uint32 now = SDL_GetTicks();
0b918c186938 Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
egottlieb
parents: 4837
diff changeset
36 if(next_time <= now)
0b918c186938 Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
egottlieb
parents: 4837
diff changeset
37 return 0;
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
38 else
4849
0b918c186938 Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
egottlieb
parents: 4837
diff changeset
39 return next_time - now;
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
40 }
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
41
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
42 int main(int argc,char** argv) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
43 Uint8 num_pictures;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
44 LoadedPicture* pictures;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
45 int i, j;
4817
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4816
diff changeset
46 SDL_PixelFormat* format = NULL;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
47 SDL_Window *window;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
48 SDL_Color black = {0,0,0,0xff};
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
49 SDL_Event event;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
50 int event_pending = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
51 int should_exit = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
52 unsigned int current_picture;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
53 int button_down;
4817
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4816
diff changeset
54 Uint32 pixelFormat = 0;
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4816
diff changeset
55 int access = 0;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
56 SDL_Rect texture_dimensions;;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
57
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
58 if(argc < 2) {
5032
6ccfbaef0c0a Removed extra space
Sam Lantinga <slouken@libsdl.org>
parents: 4857
diff changeset
59 printf("SDL_Shape requires at least one bitmap file as argument.\n");
6ccfbaef0c0a Removed extra space
Sam Lantinga <slouken@libsdl.org>
parents: 4857
diff changeset
60 exit(-1);
6ccfbaef0c0a Removed extra space
Sam Lantinga <slouken@libsdl.org>
parents: 4857
diff changeset
61 }
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
62
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
63 if(SDL_VideoInit(NULL,0) == -1) {
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
64 printf("Could not initialize SDL video.\n");
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
65 exit(-2);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
66 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
67
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
68 num_pictures = argc - 1;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
69 pictures = (LoadedPicture *)malloc(sizeof(LoadedPicture)*num_pictures);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
70 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
71 pictures[i].surface = NULL;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
72 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
73 pictures[i].surface = SDL_LoadBMP(argv[i+1]);
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
74 if(pictures[i].surface == NULL) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
75 j = 0;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
76 for(j=0;j<num_pictures;j++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
77 if(pictures[j].surface != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
78 SDL_FreeSurface(pictures[j].surface);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
79 free(pictures);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
80 SDL_VideoQuit();
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
81 printf("Could not load surface from named bitmap file.\n");
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
82 exit(-3);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
83 }
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
84
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
85 format = pictures[i].surface->format;
4817
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4816
diff changeset
86 if(format->Amask != 0) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
87 pictures[i].mode.mode = ShapeModeBinarizeAlpha;
4857
579dabb141ea Raised binarization cutoff to eliminate alpha-blending of trollface.
egottlieb
parents: 4849
diff changeset
88 pictures[i].mode.parameters.binarizationCutoff = 255;
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
89 }
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
90 else {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
91 pictures[i].mode.mode = ShapeModeColorKey;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
92 pictures[i].mode.parameters.colorKey = black;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
93 }
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
94 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
95
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
96 window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
97 if(window == NULL) {
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
98 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
99 SDL_FreeSurface(pictures[i].surface);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
100 free(pictures);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
101 SDL_VideoQuit();
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
102 printf("Could not create shaped window for SDL_Shape.\n");
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
103 exit(-4);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
104 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
105 if(SDL_CreateRenderer(window,-1,SDL_RENDERER_PRESENTFLIP2) == -1) {
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
106 SDL_DestroyWindow(window);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
107 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
108 SDL_FreeSurface(pictures[i].surface);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
109 free(pictures);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
110 SDL_VideoQuit();
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
111 printf("Could not create rendering context for SDL_Shape window.\n");
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
112 exit(-5);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
113 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
114
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
115 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
116 pictures[i].texture = NULL;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
117 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
118 pictures[i].texture = SDL_CreateTextureFromSurface(0,pictures[i].surface);
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
119 if(pictures[i].texture == NULL) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
120 j = 0;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
121 for(j=0;j<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
122 if(pictures[i].texture != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
123 SDL_DestroyTexture(pictures[i].texture);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
124 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
125 SDL_FreeSurface(pictures[i].surface);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
126 free(pictures);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
127 SDL_DestroyRenderer(window);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
128 SDL_DestroyWindow(window);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
129 SDL_VideoQuit();
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
130 printf("Could not create texture for SDL_shape.\n");
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
131 exit(-6);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
132 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
133 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
134
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
135 event_pending = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
136 should_exit = 0;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
137 event_pending = SDL_PollEvent(&event);
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
138 current_picture = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
139 button_down = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
140 texture_dimensions.h = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
141 texture_dimensions.w = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
142 texture_dimensions.x = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
143 texture_dimensions.y = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
144 SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
145 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
146 SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
147 next_time = SDL_GetTicks() + TICK_INTERVAL;
4800
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
148 while(should_exit == 0) {
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
149 event_pending = SDL_PollEvent(&event);
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
150 if(event_pending == 1) {
4803
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
151 if(event.type == SDL_KEYDOWN) {
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
152 button_down = 1;
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
153 if(event.key.keysym.sym == SDLK_ESCAPE)
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
154 should_exit = 1;
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
155 }
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
156 if(button_down && event.type == SDL_KEYUP) {
a4c1df880690 Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
157 button_down = 0;
4800
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
158 current_picture += 1;
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
159 if(current_picture >= num_pictures)
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
160 current_picture = 0;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
161 SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
4800
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
162 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
163 SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
4800
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
164 }
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
165 if(event.type == SDL_QUIT)
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
166 should_exit = 1;
6d4be626225f Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4799
diff changeset
167 event_pending = 0;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
168 }
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
169 render(window,pictures[current_picture].texture,texture_dimensions);
4805
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
170 SDL_Delay(time_left());
de3b3455f8ec Put the render loop back in its right place, but with delaying functionality to keep it down to roughly 60fps, not eating up all the X11 time.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4804
diff changeset
171 next_time += TICK_INTERVAL;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
172 }
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
173
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
174 //Free the textures.
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
175 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
176 SDL_DestroyTexture(pictures[i].texture);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
177 //Destroy the window.
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
178 SDL_DestroyWindow(window);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
179 //Free the original surfaces backing the textures.
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
180 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
181 SDL_FreeSurface(pictures[i].surface);
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
182 free(pictures);
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
183 //Call SDL_VideoQuit() before quitting.
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
184 SDL_VideoQuit();
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
185
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
186 return 0;
4799
a0e096916474 Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
187 }