Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: PerlGameDev/SDL2
base: 97204a553e
...
head fork: PerlGameDev/SDL2
compare: 7e574dc861
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
8 Build.PL
@@ -33,8 +33,16 @@ my %subsystems = (
to => 'lib/SDL2/Renderer.xs',
},
libraries => [qw( SDL2 )],
+ },
+ Rect => {
+ file => {
+ from => 'src/Core/objects/Rect.xs',
+ to => 'lib/SDL2/Rect.xs',
+ },
+ libraries => [qw( SDL2 )],
}
+
);
View
16 lib/SDL2/Rect.pm
@@ -0,0 +1,16 @@
+package SDL2::Rect;
+use strict;
+use warnings;
+use vars qw(@ISA @EXPORT @EXPORT_OK);
+require Exporter;
+require DynaLoader;
+our @ISA = qw(Exporter DynaLoader);
+
+use SDL2::Internal::Loader;
+internal_load_dlls(__PACKAGE__);
+
+bootstrap SDL2::Rect;
+
+use base 'Exporter';
+
+1;
View
83 src/Core/objects/Rect.xs
@@ -0,0 +1,83 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#include "ppport.h"
+#include "helper.h"
+
+#ifndef aTHX_
+#define aTHX_
+#endif
+
+#include <SDL2/SDL.h>
+
+MODULE = SDL2::Rect PACKAGE = SDL2::Rect PREFIX = rect_
+
+=for documentation
+
+SDL_Rect -- Defines a rectangular area
+
+ typedef struct{
+ Sint16 x, y;
+ Uint16 w, h;
+ } SDL_Rect;
+
+=cut
+
+SDL_Rect *
+rect_new (CLASS, x, y, w, h)
+ char* CLASS
+ Sint16 x
+ Sint16 y
+ Uint16 w
+ Uint16 h
+ CODE:
+ RETVAL = (SDL_Rect *) safemalloc (sizeof(SDL_Rect));
+ RETVAL->x = x;
+ RETVAL->y = y;
+ RETVAL->w = w;
+ RETVAL->h = h;
+ OUTPUT:
+ RETVAL
+
+Sint16
+rect_x ( rect, ... )
+ SDL_Rect *rect
+ CODE:
+ if (items > 1 ) rect->x = SvIV(ST(1));
+ RETVAL = rect->x;
+ OUTPUT:
+ RETVAL
+
+Sint16
+rect_y ( rect, ... )
+ SDL_Rect *rect
+ CODE:
+ if (items > 1 ) rect->y = SvIV(ST(1));
+ RETVAL = rect->y;
+ OUTPUT:
+ RETVAL
+
+Uint16
+rect_w ( rect, ... )
+ SDL_Rect *rect
+ CODE:
+ if (items > 1 ) rect->w = SvIV(ST(1));
+ RETVAL = rect->w;
+ OUTPUT:
+ RETVAL
+
+Uint16
+rect_h ( rect, ... )
+ SDL_Rect *rect
+ CODE:
+ if (items > 1 ) rect->h = SvIV(ST(1));
+ RETVAL = rect->h;
+ OUTPUT:
+ RETVAL
+
+
+void
+rect_DESTROY(bag)
+ SV *bag
+ CODE:
+ objDESTROY(bag, safefree);
View
50 src/Core/objects/Renderer.xs
@@ -26,11 +26,59 @@ renderer_new (CLASS, window, index, flags)
Uint32 flags
CODE:
SDL_Renderer* renderer = SDL_CreateRenderer(window, index, flags);
- //warn( "Made renderer %p", renderer);
+ if( renderer == NULL )
+ warn( "ERROR making renderer: %s", SDL_GetError() );
RETVAL = renderer;
OUTPUT:
RETVAL
+int
+renderer_clear ( renderer )
+ SDL_Renderer* renderer
+ CODE:
+ RETVAL = SDL_RenderClear( renderer );
+ OUTPUT:
+ RETVAL
+
+int
+renderer_draw_rect (renderer, rect)
+ SDL_Renderer* renderer
+ SDL_Rect* rect
+ CODE:
+ RETVAL = SDL_RenderDrawRect(renderer, rect);
+ OUTPUT:
+ RETVAL
+
+
+int
+renderer_fill_rect (renderer, rect)
+ SDL_Renderer* renderer
+ SDL_Rect* rect
+ CODE:
+ RETVAL = SDL_RenderFillRect(renderer, rect);
+ OUTPUT:
+ RETVAL
+
+
+void
+renderer_present ( renderer )
+ SDL_Renderer* renderer
+ CODE:
+ SDL_RenderPresent( renderer );
+
+int
+renderer_set_draw_color (renderer, r, g, b, a)
+ SDL_Renderer* renderer
+ Uint8 r
+ Uint8 g
+ Uint8 b
+ Uint8 a
+ CODE:
+ RETVAL = SDL_SetRenderDrawColor(renderer, r, g, b, a);
+ OUTPUT:
+ RETVAL
+
+
void
renderer_DESTROY(bag)
SV *bag
View
6 src/SDL2pp.xs
@@ -58,10 +58,10 @@ was_init ( flags )
OUTPUT:
RETVAL
-IV
-get_handle ()
+char*
+get_error ()
CODE:
- RETVAL = 0;
+ RETVAL = SDL_GetError();
OUTPUT:
RETVAL
View
22 t/001_load.t
@@ -2,15 +2,16 @@
# t/001_load.t - check module loading and create testing directory
-use Test::More tests => 4;
+use Test::More tests => 5;
BEGIN {
use_ok( 'SDL2pp' );
use_ok( 'SDL2::Window' );
use_ok( 'SDL2::Renderer' );
+ use_ok( 'SDL2::Rect' );
}
-SDL2pp::init(0);
+exit 0 if SDL2pp::init(0x00000020) < 0 ; #SDL_INIT_VIDEO
my $window_flags => { SDL_WINDOW_FULLSCREEN => 0x00000001,
SDL_WINDOW_OPENGL => 0x00000002,
@@ -29,10 +30,25 @@ my $window_flags => { SDL_WINDOW_FULLSCREEN => 0x00000001,
my $win = SDL2::Window->new("FIRST WINDOW", 50, 50, 200, 200, $window_flags->{SDL_WINDOW_SHOWN} | $window_flags->{SDL_WINDOW_OPENGL});
-my $renderer = SDL2::Renderer->new($win, -1, 0);
+my $renderer = SDL2::Renderer->new($win, -1, 0x00000002); #Hardware accelerated with software fallback
+
+my $rect = SDL2::Rect->new(0,0,4,4);
+
+warn $renderer->set_draw_color(255,0,0,255);
+
+warn $renderer->clear();
+
+warn $renderer->set_draw_color(0, 255,0,255);
+
+warn $renderer->fill_rect($rect);
+
+my $rect2 = SDL2::Rect->new(4,4,10,10);
+
+warn $renderer->draw_rect($rect);
SDL2pp::delay(3000);
SDL2pp::quit();
+warn "FINISHED: ". SDL2pp::get_error();
pass();
View
54 t/002_software.t
@@ -0,0 +1,54 @@
+# -*- perl -*-
+
+# t/001_load.t - check module loading and create testing directory
+
+use Test::More tests => 5;
+
+BEGIN {
+ use_ok( 'SDL2pp' );
+ use_ok( 'SDL2::Window' );
+ use_ok( 'SDL2::Renderer' );
+ use_ok( 'SDL2::Rect' );
+ }
+
+exit 0 if SDL2pp::init(0x00000020) < 0 ; #SDL_INIT_VIDEO
+
+my $window_flags => { SDL_WINDOW_FULLSCREEN => 0x00000001,
+ SDL_WINDOW_OPENGL => 0x00000002,
+ SDL_WINDOW_SHOWN => 0x00000004,
+ SDL_WINDOW_HIDDEN => 0x00000008,
+ SDL_WINDOW_BORDERLESS => 0x00000010,
+ SDL_WINDOW_RESIZABLE => 0x00000020,
+ SDL_WINDOW_MINIMIZED => 0x00000040,
+ SDL_WINDOW_MAXIMIZED => 0x00000080,
+ SDL_WINDOW_INPUT_GRABBED => 0x00000100,
+ SDL_WINDOW_INPUT_FOCUS => 0x00000200,
+ SDL_WINDOW_MOUSE_FOCUS => 0x00000400,
+ SDL_WINDOW_FULLSCREEN_DESKTOP => ( 0x00000001 | 0x00001000 ),
+ SDL_WINDOW_FOREIGN => 0x00000800
+};
+
+my $win = SDL2::Window->new("FIRST WINDOW", 50, 50, 200, 200, $window_flags->{SDL_WINDOW_SHOWN} );
+
+my $renderer = SDL2::Renderer->new($win, -1, 0x00000001); #Hardware accelerated with software fallback
+
+my $rect = SDL2::Rect->new(0,0,4,4);
+
+warn $renderer->set_draw_color(255,0,0,255);
+
+warn $renderer->clear();
+
+warn $renderer->set_draw_color(0, 255,0,255);
+
+warn $renderer->fill_rect($rect);
+
+my $rect2 = SDL2::Rect->new(4,4,10,10);
+
+warn $renderer->draw_rect($rect);
+
+SDL2pp::delay(3000);
+
+SDL2pp::quit();
+warn "FINISHED: ". SDL2pp::get_error();
+
+pass();

No commit comments for this range

Something went wrong with that request. Please try again.