annotate test/testshape.c @ 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.
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 26 Jul 2010 17:27:04 -0400
parents 2ae79ed78a5a
children eb433f0d2ac5
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>
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
3 #include <SDL_events.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
4 #include <SDL_rect.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
5 #include <SDL_pixels.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
6 #include <SDL_video.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
7 #include <SDL_shape.h>
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
8 #include <SDL_keysym.h>
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
9 #include <SDL_timer.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
10
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
11 #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
12 #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
13 #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
14
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
15 #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
16
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
17 typedef struct LoadedPicture {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
18 SDL_Surface *surface;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
19 SDL_Texture *texture;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
20 SDL_WindowShapeMode mode;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
21 } LoadedPicture;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
22
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
23 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
24 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
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 //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
27 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
28 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
29
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 //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
31 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
32
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
33 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
34 }
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
35
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
36 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
37
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 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
39 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
40 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
41 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
42 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
43 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
44 }
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
45
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
46 int main(int argc,char** argv) {
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
47 if(argc < 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
48 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
49 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
50 }
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
51
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
52 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
53 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
54 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
55 }
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
56
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
57 Uint8 num_pictures = argc - 1;
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
58 LoadedPicture* pictures = 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
59 int i = 0;
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 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
61 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
62 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
63 pictures[i].surface = SDL_LoadBMP(argv[i+1]);
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
64 if(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
65 int j = 0;
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 for(j=0;j<num_pictures;j++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
67 if(pictures[j].surface != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
68 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
69 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
70 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
71 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
72 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
73 }
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
74 SDL_PixelFormat* format = pictures[i].surface->format;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
75 Uint32 format_enum = SDL_MasksToPixelFormatEnum (format->BitsPerPixel,format->Rmask,format->Gmask, format->Bmask,format->Amask);
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
76 if(SDL_ISPIXELFORMAT_ALPHA(format_enum)) {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
77 pictures[i].mode.mode = ShapeModeBinarizeAlpha;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
78 pictures[i].mode.parameters.binarizationCutoff = 1;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
79 }
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
80 else {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
81 pictures[i].mode.mode = ShapeModeColorKey;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
82 SDL_Color black = {0,0,0,0xff};
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
83 pictures[i].mode.parameters.colorKey = black;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
84 }
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
85 }
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
86
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
87 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);
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
88 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
89 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
90 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
91 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
92 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
93 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
94 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
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 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
97 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
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 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
103 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
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
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 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
107 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
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 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
110 if(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
111 int j = 0;
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 for(j=0;j<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
113 if(pictures[i].texture != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
114 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
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 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
117 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
118 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
119 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
120 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
121 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
122 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
123 }
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 }
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
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 SDL_Event event;
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
127 int event_pending = 0,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
128 event_pending = SDL_PollEvent(&event);
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 unsigned int current_picture = 0;
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_WindowShapeMode mode = {ShapeModeDefault,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
131 int button_down = 0;
4802
f14a8c05f5bb Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4800
diff changeset
132 Uint32 format = 0,access = 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
133 SDL_Rect texture_dimensions = {0,0,0,0};
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
134 SDL_QueryTexture(pictures[current_picture].texture,&format,&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
135 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
136 SDL_SetWindowShape(window,pictures[current_picture].surface,&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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 }
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
146 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
147 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
148 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
149 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
150 current_picture = 0;
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
151 SDL_QueryTexture(pictures[current_picture].texture,&format,&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
152 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
153 SDL_SetWindowShape(window,pictures[current_picture].surface,&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
154 }
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
155 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
156 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
157 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
158 }
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
159 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
160 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
161 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
162 }
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
163
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
164 //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
165 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
166 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
167 //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
168 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
169 //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
170 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
171 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
172 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
173 //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
174 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
175 }