From: Ben Beltran Date: Wed, 14 Aug 2013 03:01:37 +0000 (-0500) Subject: Rotation! X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/commitdiff_plain/ed603039c4a456b37aefe434a3b1a5352362d86b?ds=inline;hp=--cc Rotation! --- ed603039c4a456b37aefe434a3b1a5352362d86b diff --git a/Super Polarity.xcodeproj/project.pbxproj b/Super Polarity.xcodeproj/project.pbxproj index 5b989b0..364ccf7 100644 --- a/Super Polarity.xcodeproj/project.pbxproj +++ b/Super Polarity.xcodeproj/project.pbxproj @@ -13,17 +13,20 @@ 8E9D792817BA690700C76DC9 /* SDL2_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E9D792317BA690700C76DC9 /* SDL2_net.framework */; }; 8E9D792917BA690700C76DC9 /* SDL2_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E9D792417BA690700C76DC9 /* SDL2_ttf.framework */; }; 8E9D792A17BA690700C76DC9 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E9D792517BA690700C76DC9 /* SDL2.framework */; }; + 8EC3B7BA17BB185D00D3BDD0 /* ben.png in Copy Static Images */ = {isa = PBXBuildFile; fileRef = 8EC3B7B917BB185700D3BDD0 /* ben.png */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ - 8E9D78E717BA63F400C76DC9 /* CopyFiles */ = { + 8E9D78E717BA63F400C76DC9 /* Copy Static Images */ = { isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; + buildActionMask = 12; + dstPath = data/img/static; + dstSubfolderSpec = 16; files = ( + 8EC3B7BA17BB185D00D3BDD0 /* ben.png in Copy Static Images */, ); - runOnlyForDeploymentPostprocessing = 1; + name = "Copy Static Images"; + runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ @@ -36,6 +39,7 @@ 8E9D792317BA690700C76DC9 /* SDL2_net.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_net.framework; path = vendor/frameworks/SDL2_net.framework; sourceTree = ""; }; 8E9D792417BA690700C76DC9 /* SDL2_ttf.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_ttf.framework; path = vendor/frameworks/SDL2_ttf.framework; sourceTree = ""; }; 8E9D792517BA690700C76DC9 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = vendor/frameworks/SDL2.framework; sourceTree = ""; }; + 8EC3B7B917BB185700D3BDD0 /* ben.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ben.png; path = data/img/static/ben.png; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,6 +61,7 @@ 8E9D78E017BA63F400C76DC9 = { isa = PBXGroup; children = ( + 8EC3B7B617BB183500D3BDD0 /* data */, 8E9D792117BA690700C76DC9 /* SDL2_image.framework */, 8E9D792217BA690700C76DC9 /* SDL2_mixer.framework */, 8E9D792317BA690700C76DC9 /* SDL2_net.framework */, @@ -84,6 +89,30 @@ path = src; sourceTree = ""; }; + 8EC3B7B617BB183500D3BDD0 /* data */ = { + isa = PBXGroup; + children = ( + 8EC3B7B717BB183900D3BDD0 /* img */, + ); + name = data; + sourceTree = ""; + }; + 8EC3B7B717BB183900D3BDD0 /* img */ = { + isa = PBXGroup; + children = ( + 8EC3B7B817BB183E00D3BDD0 /* static */, + ); + name = img; + sourceTree = ""; + }; + 8EC3B7B817BB183E00D3BDD0 /* static */ = { + isa = PBXGroup; + children = ( + 8EC3B7B917BB185700D3BDD0 /* ben.png */, + ); + name = static; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -93,7 +122,7 @@ buildPhases = ( 8E9D78E517BA63F400C76DC9 /* Sources */, 8E9D78E617BA63F400C76DC9 /* Frameworks */, - 8E9D78E717BA63F400C76DC9 /* CopyFiles */, + 8E9D78E717BA63F400C76DC9 /* Copy Static Images */, ); buildRules = ( ); @@ -204,10 +233,12 @@ 8E9D78F317BA63F400C76DC9 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/vendor/frameworks\"", ); + MACH_O_TYPE = mh_execute; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -215,10 +246,12 @@ 8E9D78F417BA63F400C76DC9 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/vendor/frameworks\"", ); + MACH_O_TYPE = mh_execute; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Super Polarity.xcodeproj/project.xcworkspace/xcuserdata/benbeltran.xcuserdatad/UserInterfaceState.xcuserstate b/Super Polarity.xcodeproj/project.xcworkspace/xcuserdata/benbeltran.xcuserdatad/UserInterfaceState.xcuserstate index fe37881..11dbff6 100644 Binary files a/Super Polarity.xcodeproj/project.xcworkspace/xcuserdata/benbeltran.xcuserdatad/UserInterfaceState.xcuserstate and b/Super Polarity.xcodeproj/project.xcworkspace/xcuserdata/benbeltran.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/main.c b/src/main.c index 602dff3..b51a79d 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include #include +#include #include "SDL2/SDL.h" #include "SDL2_image/SDL_image.h" @@ -19,7 +20,9 @@ SDL_Window *window; SDL_Renderer *renderer; -SDL_Surface *benHead; +SDL_Texture *benHead; +SDL_Rect benRect; +double angle = 0; void init () { if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -35,25 +38,51 @@ void init () { // Set linear quality for scaling, and the "logical" window size. SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT); - +} + +void close () { + SDL_DestroyTexture(benHead); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); +} + +void loadAssets() { // Load the surface. - // benHead = IMG_Load("data/img/static/ben.png"); + SDL_Surface *benSurface; + benSurface = IMG_Load("data/img/static/ben.png"); + benHead = SDL_CreateTextureFromSurface(renderer, benSurface); + benRect.x = 230; + benRect.y = 150; + benRect.w = 180; + benRect.h = 180; + SDL_FreeSurface(benSurface); } void render (SDL_Renderer *renderer) { SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_RenderClear(renderer); + SDL_RenderCopyEx(renderer, benHead, NULL, &benRect, angle, NULL, SDL_FLIP_NONE); SDL_RenderPresent(renderer); } -int mainC(int argc, const char * argv[]) +void update (dt) { + angle = (Uint32)(angle + dt / 5) % 360; +} + +int main(int argc, const char * argv[]) { // SDL Initialization. TODO: Should have an initializer. - Uint32 startFrame; - Uint32 endFrame; + Uint32 startFrame = 0; + Uint32 endFrame = 0; + Uint32 lastTime = 0; + Uint32 dt; Uint32 delay; int done; + + init(); + loadAssets(); done = 0; @@ -61,6 +90,9 @@ int mainC(int argc, const char * argv[]) // Event Loop. while (!done) { startFrame = SDL_GetTicks(); + dt = startFrame - lastTime; + lastTime = startFrame; + SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { @@ -68,6 +100,7 @@ int mainC(int argc, const char * argv[]) } } + update(dt); render(renderer); endFrame = SDL_GetTicks(); @@ -80,7 +113,7 @@ int mainC(int argc, const char * argv[]) SDL_Delay(delay); } - SDL_Quit(); + close(); return 0; }