annotate test/testshape.c @ 4816:eb433f0d2ac5

Added Andreas's VS2010 patch for testshape.
author Eli Gottlieb <eligottlieb@gmail.com>
date Fri, 30 Jul 2010 18:04:21 -0400
parents 329708ffe2a7
children c68e7490e4cf
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;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
46 SDL_PixelFormat* format;
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;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
55 Uint32 pixelFormat;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
56 int access;
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;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
87 format_enum = SDL_MasksToPixelFormatEnum (format->BitsPerPixel,format->Rmask,format->Gmask, format->Bmask,format->Amask);
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
88 if(SDL_ISPIXELFORMAT_ALPHA(format_enum)) {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
89 pictures[i].mode.mode = ShapeModeBinarizeAlpha;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
90 pictures[i].mode.parameters.binarizationCutoff = 1;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
91 }
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
92 else {
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
93 pictures[i].mode.mode = ShapeModeColorKey;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
94 pictures[i].mode.parameters.colorKey = black;
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
95 }
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
96 }
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
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
98 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
99 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
100 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
101 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
102 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
103 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
104 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
105 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
106 }
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 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
108 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
109 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
110 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
111 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
112 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
113 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
114 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
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
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 = 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
119 for(i=0;i<num_pictures;i++) {
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
120 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
121 if(pictures[i].texture == NULL) {
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
122 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
123 for(j=0;j<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
124 if(pictures[i].texture != NULL)
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
125 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
126 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
127 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
128 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
129 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
130 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
131 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
132 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
133 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
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 }
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
136
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
137 event_pending = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
138 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
139 event_pending = SDL_PollEvent(&event);
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
140 current_picture = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
141 button_down = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
142 format = 0,access = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
143 texture_dimensions.h = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
144 texture_dimensions.w = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
145 texture_dimensions.x = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
146 texture_dimensions.y = 0;
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 }
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
159 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
160 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
161 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
162 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
163 current_picture = 0;
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
164 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
165 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
166 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
167 }
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 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
169 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
170 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
171 }
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
172 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
173 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
174 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
175 }
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
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 //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
178 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
179 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
180 //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
181 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
182 //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
183 for(i=0;i<num_pictures;i++)
4808
2ae79ed78a5a More work on color-key mode.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4805
diff changeset
184 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
185 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
186 //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
187 SDL_VideoQuit();
4816
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
188
eb433f0d2ac5 Added Andreas's VS2010 patch for testshape.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
189 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
190 }