The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Q&A from a guy migrating to SDL2
bazz


Joined: 25 Oct 2010
Posts: 31
I am going to be getting deep inside SDL2 (why cant she be a hot sexy girl) She's close enough Smile
Before I do that, I assume it would be of good etiquette to provide some background on me as a software developer, so that I may show that I am experienced. I am currently a college undergrad @ UmassBoston studying computer science, and have been programming since I was 10. I started about the time I found BASIC on a computer in elementary school, sporting the hit game BANANA



Nice.. My friends somehow figured out how to run it. And I thought it was cool that the code was there to show you how it works. I of course didn't understand much, but that was the upside. I like to learn Smile I wanted to make my own video game Smile

I fondly remember walking through Borders book store with my mom and I would go strraight to the computers section. I ended up picking up a book, Linus Torvald's auto-b called Just for Fun. Somehow I really looked up to him, probably only cause it reaffirmed my habits with a positive light. Staying up late coding, learning, etc. Smile Linus always said he believed in a good night's sleep. Man will I ever learn how to do that Smile hahahahah

Anyways flash forward.. You learn a zillion languages and somehow God places you heree. on a SDL forum.. because you picked up your old game from highschool that was in SDL 1.2 .. you were bored cause you were on break and I say to myself, "im gonna bring her back" Smile So i did, and now I'm here. I want to make a hit video game Smile I want to Make it Meatball Smile

Migrating from SDL 1.2.15 to SDL2
Aside from using http://wiki.libsdl.org/moin.cgi/MigrationGuide



1) Migrating from Surfaces -> Renderers and Textures

The way I take is, I do all initial sprite image operations with a Surface, and finally make it a texture. If the sprite has to change, destroy the texture, do surface operations, make a new texture.

This has been great so far..

I only use 1 Renderer for everything. I do SDL_RenderCopy for all the textures... Finally doing a RenderPresent to get everything onto the window.
Of course, I am doing RenderClear for the first operation in the Main drawing loop to clear the screen.

Also, I am loving the Pixel operations.. No need for textures/surfaces, just set the Color for the Renderer with alpha all-in-one and draw pixel. Nice Smile
for alpha you can just
Code:
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);


to preserve the drawing color of your renderer and put a new pixel, do something like the following:
Code:
Uint8 oor,og,ob,oa;
   
   // Save color
   SDL_GetRenderDrawColor(renderer, &oor, &og, &ob, &oa);
   // Set new Color
   SDL_SetRenderDrawColor(renderer, (Uint8)red, (Uint8)green, (Uint8)blue, (Uint8)alpha);
   
   // Draw the point
   SDL_RenderDrawPoint(renderer, (int)( posx - pCamera->x ), (int)( posy - pCamera->y ));
   // Restore old color
   SDL_SetRenderDrawColor(renderer, oor, og, ob, oa);



Afterthoughts- -- - The search for Answers
ie One Renderer seems fulfilling for now. I havent yet thought of reasons to use many except for Aesthetics or seperating sections, but mainly for the sake of organization. Like ie. have a renderer just for the HUd in my game. But besides organization, I don't see much usefulness of several Renderers.... do you?

Also, I am very surprised by the lack of support for SDL2.. Thank God I am in a position to Read manuals like it's my job Smile Another place that helped me get started was https://github.com/crust/sdl2-examples
And if you really want to start from scratch (and learn some new C++ standards) then you can try http://twinklebeardev.blogspot.com/p/sdl-20-tutorial-index.html


having specifically migrated on the OSX 10.8.2 Mountain Lion using XCode 4.5.2, I am going to provide my personal adventure tidbits of getting everything installed and also I figured an easy fix for doing X11 optional support for compiling under XCode, which was not presently available. Again, I will be posting these in another thread. Stay posted.

Cheers!