annotate test/testshape.c @ 4835:40b5293d0598

Finally figured out how to use autorelease pools.
author egottlieb
date Thu, 05 Aug 2010 21:27:32 -0400
parents c68e7490e4cf
children 2e446923c9fb
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
4809
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4808
diff changeset
11 #define TICK_INTERVAL 1000/60
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() {
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
35 Uint32 now = SDL_GetTicks();
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
36 if(next_time <= now)
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
37 return 0;
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
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
39 return next_time - now;
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 Uint32 format_enum;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
48 SDL_Window *window;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
49 SDL_Color black = {0,0,0,0xff};
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
50 SDL_Event event;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
51 int event_pending = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
52 int should_exit = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
53 unsigned int current_picture;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
54 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
55 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
56 int access = 0;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
57 SDL_Rect texture_dimensions;;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
58
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
59 if(argc < 2) {
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
60 printf("SDL_Shape requires at least one bitmap file as argument.\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
61 exit(-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
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
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 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
65 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
66 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
67 }
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
68
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
69 num_pictures = argc - 1;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
70 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
71 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
72 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
73 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
74 pictures[i].surface = SDL_LoadBMP(argv[i+1]);
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
75 if(pictures[i].surface == NULL) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
76 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
77 for(j=0;j<num_pictures;j++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
78 if(pictures[j].surface != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
79 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
80 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
81 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
82 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
83 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
84 }
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
85
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
86 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
87 if(format->Amask != 0) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
88 pictures[i].mode.mode = ShapeModeBinarizeAlpha;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
89 pictures[i].mode.parameters.binarizationCutoff = 1;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
90 }
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
91 else {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
92 pictures[i].mode.mode = ShapeModeColorKey;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
93 pictures[i].mode.parameters.colorKey = black;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
94 }
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
95 }
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
96
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
97 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
98 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
99 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
100 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
101 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
102 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
103 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
104 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
105 }
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 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
107 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
108 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
109 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
110 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
111 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
112 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
113 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
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
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
116 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
117 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
118 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
119 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
120 if(pictures[i].texture == NULL) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
121 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
122 for(j=0;j<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
123 if(pictures[i].texture != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
124 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
125 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
126 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
127 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
128 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
129 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
130 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
131 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
132 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
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 }
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
135
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
136 event_pending = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
137 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
138 event_pending = SDL_PollEvent(&event);
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
139 current_picture = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
140 button_down = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
141 texture_dimensions.h = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
142 texture_dimensions.w = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
143 texture_dimensions.x = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
144 texture_dimensions.y = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 }
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 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
158 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
159 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
160 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
161 current_picture = 0;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
162 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
163 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
164 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
165 }
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 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
167 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
168 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
169 }
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
170 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
171 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
172 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
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
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 //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
176 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
177 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
178 //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
179 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
180 //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
181 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
182 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
183 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
184 //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
185 SDL_VideoQuit();
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
186
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
187 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
188 }