- Bugs I encountered with SDL - SDL_Delay not delaying long enough (need a while loop around it) - Because they call Win32's "Sleep()" directly, but that doesn't necesarrily sleep for the requested amount of time. - Fix: use a while loop - My glTexImageTGAFile function not working with alpha channels - Fix: change the code - (Note: my fix was incorrect, I have uploaded a correct fix in its place) - 2D Animation Techniques - Simple frame animation - At startup: - Load up an array of textures, one for each frame of animation - Load up an array of index/delay pairs, which say how long to be on each frame - At runtime: - Update, per sprite object: - Decrement the remaining time - If remaining time is less than zero, move to the next frame - Render, per sprite object: - Draw the current index'd texture - Multi-frame - Have multiple frames used simultaneously to create more detailed animations without tons of space (Like Gunstar Heroes' 7 force) - At startup, just like Simple with following additions: - Array of index/delay pairs becomes array of (list of (index, 2D offset), delay) - At runtime, just like Simple with following additions: - Update, per sprite object: - Just like Simple - Render, per sprite object: - Draw each current index'd texture at the position offset by 2D offset - May want to LERP between positions to create smoother animations - Skeletal Animation - Like Multi-frame, but 2D offset is instead a heirarchial list of matrices (can do rotations, too) - Each texture would have one bone pos - In 3D a bone corresponds to multiple verts - At startup, just like Multi with the following additions: - list of (index, 2D offset) becomes tree of (index, matrix) - At runtime, just like Multi with the following additions: - Update, per sprite object: - Just like multi - Render, per sprite object: - Traverse the tree, recursively applying matrices at each bone to get a final matrix. This is the matrix you pass into drawSprite(). - Almost certainly want to LERP between positions/rotations at runtime to create smooth animation - Did not discuss how to do this, if you want to please talk to me. - OpenGL Blending modes - Controlled by two functions: - glBlendFunc() - glBlendEquation() - To enable you must call glEnable( GL_BLEND )! - You may want to use alpha testing to reduce pixels processed: - glEnable( GL_ALPHA_TEST ) - glAlphaFunc( GL_GREATER, 2 / 255.0 ) - Will reject any pixel with alpha value <= 2 - Alpha Blending - What you normally see in games to make things look transparent - Doesn't really map to any physical process quite right -- closest is glass / water without reflection - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) - glBlendEquation( GL_FUNC_ADD ) - Additive Blending - Used for things like fire, where light combines to become brighter - glBlendFunc( GL_SRC_ALPHA, GL_ONE ) - glBlendEquation( GL_FUNC_ADD ) - Subtractive blending - Opposite of Additive, useful for darkness "clouds" - glBlendFunc( GL_SRC_ALPHA, GL_ONE ) - glBlendEquation( GL_FUNC_REVERSE_SUBTRACT ) - Inversion Blending - Used to invert colors - Requires ALPHA_TEST if you want to invert shapes - glBlendFunc( GL_ONE, GL_ONE ) - glBlendEquation( GL_FUNC_SUBTRACT ) - Particle Systems - Use programatic randomness to create cool looking effects - Biggest thing: "fire and forget", you call spawnParticles(...) and the system knows how to update them - Per particle you will want to store - Position - Velocity - Acceleration (maybe) - Mod color - Mod color velocity (maybe) - Time to live - Per system you will want to store - List of active particles - Texture to use (may be per-particle) - Blend mode - At runtime - When you want particles (either constantly or when an event happens): - call spawnParticles, give initial values for all per-particle values - Update, per particle system: - Update each particle's per particle value - Maybe collide with world - Render, per particle system: - Draw each particle with its current state