mirror of
https://github.com/joel16/SDL2.git
synced 2025-04-13 03:50:18 +00:00

--HG-- rename : README.iphoneos => README.iOS rename : Xcode-iPhoneOS/Demos/Default.png => Xcode-iOS/Demos/Default.png rename : Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj => Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj rename : Xcode-iPhoneOS/Demos/Icon.png => Xcode-iOS/Demos/Icon.png rename : Xcode-iPhoneOS/Demos/Info.plist => Xcode-iOS/Demos/Info.plist rename : Xcode-iPhoneOS/Demos/README => Xcode-iOS/Demos/README rename : Xcode-iPhoneOS/Demos/data/bitmapfont/kromasky_16x16.bmp => Xcode-iOS/Demos/data/bitmapfont/kromasky_16x16.bmp rename : Xcode-iPhoneOS/Demos/data/bitmapfont/license.txt => Xcode-iOS/Demos/data/bitmapfont/license.txt rename : Xcode-iPhoneOS/Demos/data/drums/ds_brush_snare.wav => Xcode-iOS/Demos/data/drums/ds_brush_snare.wav rename : Xcode-iPhoneOS/Demos/data/drums/ds_china.wav => Xcode-iOS/Demos/data/drums/ds_china.wav rename : Xcode-iPhoneOS/Demos/data/drums/ds_kick_big_amb.wav => Xcode-iOS/Demos/data/drums/ds_kick_big_amb.wav rename : Xcode-iPhoneOS/Demos/data/drums/ds_loose_skin_mute.wav => Xcode-iOS/Demos/data/drums/ds_loose_skin_mute.wav rename : Xcode-iPhoneOS/Demos/data/icon.bmp => Xcode-iOS/Demos/data/icon.bmp rename : Xcode-iPhoneOS/Demos/data/ship.bmp => Xcode-iOS/Demos/data/ship.bmp rename : Xcode-iPhoneOS/Demos/data/space.bmp => Xcode-iOS/Demos/data/space.bmp rename : Xcode-iPhoneOS/Demos/data/stroke.bmp => Xcode-iOS/Demos/data/stroke.bmp rename : Xcode-iPhoneOS/Demos/src/accelerometer.c => Xcode-iOS/Demos/src/accelerometer.c rename : Xcode-iPhoneOS/Demos/src/common.c => Xcode-iOS/Demos/src/common.c rename : Xcode-iPhoneOS/Demos/src/common.h => Xcode-iOS/Demos/src/common.h rename : Xcode-iPhoneOS/Demos/src/fireworks.c => Xcode-iOS/Demos/src/fireworks.c rename : Xcode-iPhoneOS/Demos/src/happy.c => Xcode-iOS/Demos/src/happy.c rename : Xcode-iPhoneOS/Demos/src/keyboard.c => Xcode-iOS/Demos/src/keyboard.c rename : Xcode-iPhoneOS/Demos/src/mixer.c => Xcode-iOS/Demos/src/mixer.c rename : Xcode-iPhoneOS/Demos/src/rectangles.c => Xcode-iOS/Demos/src/rectangles.c rename : Xcode-iPhoneOS/Demos/src/touch.c => Xcode-iOS/Demos/src/touch.c rename : Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj => Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj rename : Xcode-iPhoneOS/SDL/testsdl-Info.plist => Xcode-iOS/SDL/testsdl-Info.plist rename : Xcode-iPhoneOS/Template/SDL iOS Application/Default.png => Xcode-iOS/Template/SDL iOS Application/Default.png rename : Xcode-iPhoneOS/Template/SDL iOS Application/Icon.png => Xcode-iOS/Template/SDL iOS Application/Icon.png rename : Xcode-iPhoneOS/Template/SDL iOS Application/Info.plist => Xcode-iOS/Template/SDL iOS Application/Info.plist rename : Xcode-iPhoneOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/TemplateIcon.icns => Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/TemplateIcon.icns rename : Xcode-iPhoneOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/TemplateInfo.plist => Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/TemplateInfo.plist rename : Xcode-iPhoneOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj => Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj rename : Xcode-iPhoneOS/Template/SDL iOS Application/main.c => Xcode-iOS/Template/SDL iOS Application/main.c rename : Xcode-iPhoneOS/Test/Info.plist => Xcode-iOS/Test/Info.plist rename : Xcode-iPhoneOS/Test/README => Xcode-iOS/Test/README rename : Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj => Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
99 lines
2.0 KiB
C
99 lines
2.0 KiB
C
/*
|
|
* rectangles.c
|
|
* written by Holmes Futrell
|
|
* use however you want
|
|
*/
|
|
|
|
#include "SDL.h"
|
|
#include <time.h>
|
|
|
|
#define SCREEN_WIDTH 320
|
|
#define SCREEN_HEIGHT 480
|
|
|
|
int
|
|
randomInt(int min, int max)
|
|
{
|
|
return min + rand() % (max - min + 1);
|
|
}
|
|
|
|
void
|
|
render(SDL_Renderer *renderer)
|
|
{
|
|
|
|
Uint8 r, g, b;
|
|
|
|
/* Clear the screen */
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
SDL_RenderClear(renderer);
|
|
|
|
/* Come up with a random rectangle */
|
|
SDL_Rect rect;
|
|
rect.w = randomInt(64, 128);
|
|
rect.h = randomInt(64, 128);
|
|
rect.x = randomInt(0, SCREEN_WIDTH);
|
|
rect.y = randomInt(0, SCREEN_HEIGHT);
|
|
|
|
/* Come up with a random color */
|
|
r = randomInt(50, 255);
|
|
g = randomInt(50, 255);
|
|
b = randomInt(50, 255);
|
|
SDL_SetRenderDrawColor(renderer, r, g, b, 255);
|
|
|
|
/* Fill the rectangle in the color */
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
/* update screen */
|
|
SDL_RenderPresent(renderer);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
|
|
SDL_Window *window;
|
|
SDL_Renderer *renderer;
|
|
int done;
|
|
SDL_Event event;
|
|
|
|
/* initialize SDL */
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
printf("Could not initialize SDL\n");
|
|
return 1;
|
|
}
|
|
|
|
/* seed random number generator */
|
|
srand(time(NULL));
|
|
|
|
/* create window and renderer */
|
|
window =
|
|
SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
|
if (!window) {
|
|
printf("Could not initialize Window\n");
|
|
return 1;
|
|
}
|
|
|
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
|
if (!renderer) {
|
|
printf("Could not create renderer\n");
|
|
return 1;
|
|
}
|
|
|
|
/* Enter render loop, waiting for user to quit */
|
|
done = 0;
|
|
while (!done) {
|
|
while (SDL_PollEvent(&event)) {
|
|
if (event.type == SDL_QUIT) {
|
|
done = 1;
|
|
}
|
|
}
|
|
render(renderer);
|
|
SDL_Delay(1);
|
|
}
|
|
|
|
/* shutdown SDL */
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
}
|