Results 1 to 5 of 5

Thread: SDL Clipping

  1. #1

    SDL Clipping

    I was wondering if any of the graphics pros here might offer some guidance with a strange issue I having with SDL. I'm trying to combine the functionally of both the BBC and SDL_draw extension libraries and I have this strange issue. I was hoping I could take advantage of the BBC clipping features of the library that SDL_draw doesn't offer. Clipping works great on the vertical axis but wraps the clipped image horizontal. Searching the net I have seen OpenGL settings to control edge clipping and so on. Is there a SDL option on window creation to prevent the wrapping effect and clip like the vertical axis?
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  2. #2
    I don't know much about SDL but, the docs say you can set a clipping rectangle (prior to drawing something)

    http://search.cpan.org/~wkeenan/SDL-...ce.pm#Clipping

  3. #3
    Thanks Charles for the tip but my last attempt didn't work either. (see attached image) I used the SDL_SetClipRect hoping that would work but no luck.

      screen = SDL_SetVideoMode(width, height, 32, videoflags);
      SDL_SetClipRect(screen, NULL);
    
    Attached Images Attached Images
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  4. #4
    Well, it looks like this isn't a BBC issue as it does the same thing when using SDL_draw alone. The SDL_SetClipRect did seem to prevent the seg fault I was getting when rendering off screen without the call. If I can get by the horizontal wrapping SDL is imposing, I won't need BBC for the clipping support. Any ideas are welcome and appreciated.

    With a bit more testing it looks like it does seg fault if I render vertically off screen using SDL_draw alone. If I can solve this wrapping issue I can make SDL_draw clipping work in conjunction with the BBC extension module.

    I noticed that passing a NULL for the RECT structure disabled clipping which is the opposite effect of what I was looking for. I changed my SDL_draw window create function to pass a valid RECT structure. Here is my code that still doesn't work and wraps the image.

    SB Draw extension module source

    besFUNCTION(SDL_Draw_Window)
      DIM AS int width, height;
      DIM AS Uint32 videoflags;
      DIM AS const char PTR title;
      DIM AS SDL_Rect screct;
      SDL_Init(SDL_INIT_VIDEO);
      atexit(SDL_Quit);
      videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
      besARGUMENTS("ii[z]")
        AT width, AT height, AT title
      besARGEND
      IF (title EQ NULL) THEN_DO title = "";
      screen = SDL_SetVideoMode(width, height, 32, videoflags);
      screct.x = 0;
      screct.y = 0;
      screct.w = 800;  
      screct.h = 600;  
      SDL_SetClipRect(screen, AT screct);
      SDL_WM_SetCaption(title, 0);
      besRETURNVALUE = NULL;
    besEND
    
    Attached Images Attached Images
    Last edited by John Spikowski; 17-02-2014 at 06:21.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  5. #5
    I solved my SDL clipping issues.



    ' ScriptBasic GFX - Alpha Circles
    
    IMPORT gfx.inc
    
    gfx::Window 640, 480, "ScriptBasic GFX - Alpha Circles"
    ' Random Value Arrays
    RANDOMIZE(gfx::Time())
    FOR i = 0 TO 512
      rx[i] = RND() % 640
      ry[i] = 60 + RND() % 480 - 80
      rz[i] = RND() % 64
      rr[i] = RND() AND  255
      rg[i] = RND() AND  255
      rb[i] = RND() AND  255
      af = rx[i] / 640
      ra[i] = INT(255 * af)
    NEXT
    
    ts = gfx::Time()
    gfx::SDL_SetClipRect 0, 0, 640, 480
    FOR i = 0 TO 512
      gfx::filledCircleRGBA rx[i], ry[i], rz[i], rr[i], rg[i], rb[i], ra[i]
    NEXT
    te = gfx::Time()
    gfx::stringColor 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
    gfx::Update
    WHILE gfx::KeyName(1) <> "-escape"
    WEND
    gfx::Close
    
    Last edited by John Spikowski; 25-02-2014 at 22:29.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •