Re: Simple example for SDL2_gfx?

"joymaker" <[email protected]> Thu, 08 Dec 2016 04:28:10 +0000
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
Thanks, rtrussel, that worked great! My bug was not in the misunderstanding of the primitives, but in a misunderstanding of color specification. (I created something with an alpha of zero.)

I juiced up your examples just a little by adding some circles, here's the result. I think you should share it widely, there is a real lack of such sample code that I can find anywhere on the web!

Ken


Code:
//
//  TestGFX.c
//  SDL Examples
//
//  Created by Richard Russell (rtrussell) on 12/7/16.
//

#include <stdio.h>
#include "SDL2_gfxPrimitives.h"

#define WIDTH 1200
#define HEIGHT 900

int main(int argc, char* argv[])
{
    
    if (SDL_Init(SDL_INIT_VIDEO))
    {
        printf ("SDL_Init Error: %s", SDL_GetError());
        return 1;
    }
    
    SDL_Window *window = SDL_CreateWindow("SDL2_gfx test", 100, 100, WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
    if (window == NULL)
    {
        printf ("SDL_CreateWindow Error: %s", SDL_GetError());
        SDL_Quit();
        return 2;
    }
    
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (renderer == NULL)
    {
        SDL_DestroyWindow(window);
        printf ("SDL_CreateRenderer Error: %s", SDL_GetError());
        SDL_Quit();
        return 3;
    }
    
    SDL_Event e;
    
    int quit = 0;
    while (!quit)
    {
        if (SDL_PollEvent(&e))
        {
            if (e.type == SDL_QUIT)
                quit = 1;
        }
        SDL_SetRenderDrawColor(renderer, 0, 0, 0xFF, 0xFF);
        SDL_RenderClear(renderer);
        thickLineColor(renderer, 0, 0, WIDTH, HEIGHT, 20, 0xFF00FFFF) ;
        thickLineColor(renderer, 0, HEIGHT, WIDTH, 0, 20, 0xFF00FFFF) ;
        circleColor(renderer, WIDTH/2, HEIGHT/2, 33, 0xff00ff00);
        filledCircleColor(renderer, WIDTH/2, HEIGHT/2, 30, 0xff00ffcc);
        SDL_RenderPresent(renderer);
        SDL_Delay(10);
    }
    
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window); 
    SDL_Quit(); 
    return 0; 
}

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org