Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SDL.h"
- #include "agg_renderer_base.h"
- #include "agg_pixfmt_rgba.h"
- #include "agg_scanline_u.h"
- #include "agg_rasterizer_scanline_aa.h"
- #include "agg_renderer_scanline.h"
- #include "agg_path_storage.h"
- enum
- {
- frame_width = 800,
- frame_height = 600
- };
- int main(int argc, char * argv[])
- {
- //initialize SDL
- //--------------
- atexit(SDL_Quit);
- SDL_Init(SDL_INIT_VIDEO);
- SDL_Window* win = SDL_CreateWindow
- (
- "SDL&AGG",
- SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED,
- frame_width,
- frame_height,
- 0
- );
- SDL_Renderer* ren = SDL_CreateRenderer
- (
- win,
- -1,
- 0
- );
- //initialize AGG with memory allocated by SDL
- Uint32 rmask, gmask, bmask, amask;
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- #else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
- #endif
- SDL_Surface* surf = SDL_CreateRGBSurface
- (
- 0,
- frame_width,
- frame_height,
- 32,
- rmask,
- gmask,
- bmask,
- amask
- );
- SDL_LockSurface(surf);
- SDL_Texture* tex = SDL_CreateTexture
- (
- ren,
- SDL_PIXELFORMAT_RGBA8888,
- SDL_TEXTUREACCESS_STREAMING,
- frame_width,
- frame_height
- );
- SDL_LockTexture
- (
- tex,
- NULL,
- &surf->pixels,
- &surf->pitch
- );
- agg::rendering_buffer rbuf //rendering buffer object
- (
- (unsigned char*)surf->pixels,
- frame_width,
- frame_height,
- frame_width * 4
- );
- agg::pixfmt_rgba32 pixf(rbuf);
- agg::renderer_base<agg::pixfmt_rgba32> rbase(pixf);
- //clear surf->pixels
- rbase.clear(agg::rgba8(255, 255, 0, 0));
- agg::scanline_u8 scanline;
- agg::rasterizer_scanline_aa<> ras;
- agg::renderer_scanline_aa_solid
- <
- agg::renderer_base
- <
- agg::pixfmt_rgba32
- >
- > rscan(rbase);
- //create agg paths
- agg::path_storage path;
- path.move_to(10, 10);
- path.line_to(frame_width-10, frame_height-10);
- path.line_to(frame_width-10, 10);
- path.line_to(10, frame_height-10);
- ras.add_path(path);
- rscan.color(agg::rgba8(0, 255, 0, 255));
- //draw paths to surf->pixels
- agg::render_scanlines(ras, scanline, rscan);
- SDL_UnlockSurface(surf);
- SDL_UnlockTexture(tex);
- SDL_RenderCopy
- (
- ren,
- tex,
- NULL,
- NULL
- );
- SDL_RenderPresent(ren);
- /*
- SDL_Texture* tex2 = SDL_CreateTextureFromSurface(ren, surf);
- SDL_RenderCopy
- (
- ren,
- tex2,
- NULL,
- NULL
- );
- SDL_RenderPresent(ren);
- */
- //main event loop
- //---------------
- SDL_Event e;
- while(1) //loop until user quits
- {
- if(SDL_PollEvent(&e))
- {
- switch(e.type)
- {
- case SDL_QUIT:
- return 0;
- case SDL_KEYDOWN:
- if(e.key.keysym.sym == SDLK_ESCAPE)
- return(0);
- }
- }
- SDL_Delay(1); //speedbump, share the processor
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement