Recent

Author Topic: Why SDL_RenderDrawPoints() doesn't work?  (Read 4314 times)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Why SDL_RenderDrawPoints() doesn't work?
« on: March 18, 2018, 06:28:32 pm »
I'm new on SDL2 and maybe I'm doing something wrong, but, Can someone tell me why this code works perfectly :

Code: Pascal  [Select]
  1.  
  2.   for i := 0 to nPnts-1 do begin
  3.     SDL_RenderDrawPoint( sdlRenderer, sdlPoints1[i]^.x, sdlPoints1[i]^.y);
  4.   end;
  5.  

And this fails  >:(:

Code: Pascal  [Select]
  1.   SDL_RenderDrawPoints( sdlRenderer, sdlPoints1[0], nPnts);
  2.  

The last code just draw some points in ramdom locations of a line (apparently).

I'm using Lazarus 1.8.0 - FPC 3.0.4 in Windows 7.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Paul_

  • Full Member
  • ***
  • Posts: 130
Re: Why SDL_RenderDrawPoints() doesn't work?
« Reply #1 on: March 18, 2018, 08:53:31 pm »
"It fails" .. does not define the problem and also without rest of code and variables related to SDL_RenderDrawPoints( sdlRenderer, sdlPoints1[0], nPnts) it's hard to help.

But probably you don't have defined sdlPoints1 in right way.

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: Why SDL_RenderDrawPoints() doesn't work?
« Reply #2 on: March 18, 2018, 10:22:00 pm »
"It fails" .. does not define the problem and also without rest of code and variables related to SDL_RenderDrawPoints( sdlRenderer, sdlPoints1[0], nPnts) it's hard to help.

But probably you don't have defined sdlPoints1 in right way.

Hi.  I have a test project.

It needs SDL2.dll to compile.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Paul_

  • Full Member
  • ***
  • Posts: 130
Re: Why SDL_RenderDrawPoints() doesn't work?
« Reply #3 on: March 19, 2018, 10:44:06 am »
Original tutorial code (https://www.freepascal-meets-sdl.net/chapter-5-drawing-primitives/) shows some points but maybe only 10 instead of 500? :)

EDIT: this works for me:

Code: Pascal  [Select]
  1. var
  2.   sdlPoints1 : array[0..499] of TSDL_Point;
  3. begin
  4.   for i := 0 to 499 do begin
  5.     sdlPoints1[i].x := x + i;
  6.     sdlPoints1[i].y := y + i;
  7.   end;
  8.  
  9.   SDL_RenderDrawPoints(sdlRenderer, sdlPoints1, 500);
  10. end;

It's bit weird because function variable parameter is defined as "points: PSDL_Point"
Code: Pascal  [Select]
  1.   PSDL_Point = ^TSDL_Point;
  2.   TSDL_Point = record
  3.     x: SInt32;
  4.     y: SInt32;
  5.   end;
  6.  
  7. function SDL_RenderDrawPoints(renderer: PSDL_Renderer; points: PSDL_Point; count: SInt32): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RenderDrawPoints' {$ENDIF} {$ENDIF};
« Last Edit: March 19, 2018, 02:06:22 pm by Paul_ »

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: Why SDL_RenderDrawPoints() doesn't work?
« Reply #4 on: March 20, 2018, 02:23:51 am »
Original tutorial code (https://www.freepascal-meets-sdl.net/chapter-5-drawing-primitives/) shows some points but maybe only 10 instead of 500? :)

EDIT: this works for me:

Code: Pascal  [Select]
  1. var
  2.   sdlPoints1 : array[0..499] of TSDL_Point;
  3. begin
  4.   for i := 0 to 499 do begin
  5.     sdlPoints1[i].x := x + i;
  6.     sdlPoints1[i].y := y + i;
  7.   end;
  8.  
  9.   SDL_RenderDrawPoints(sdlRenderer, sdlPoints1, 500);
  10. end;

Yes I have been following that tutorial. Maybe it has an error and the correct form is using TSDL_Point. Considering SDL2 come from C language, it's possible some strange behaviour in Pascal.

It works for me too, using TSDL_Point. Thanks for helping.

The bad news is that using SDL_RenderDrawPoints() is as slow as using SDL_RenderDrawPoint() for each point.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: Why SDL_RenderDrawPoints() doesn't work?
« Reply #5 on: March 20, 2018, 06:03:46 pm »
The problem seems to be in the headers of SDL2, defined in: https://github.com/ev1313/Pascal-SDL-2-Headers
This is the site pointed from : https://www.freepascal-meets-sdl.net/chapter-2-installation-and-configuration/
I have found problems using SDL_LockTexture(), with that headers. I used the defined in: https://github.com/sysrpl/Bare.Game/blob/master/source/bare.interop.sdl2.pas
And SDL_LockTexture() works OK.

I think there is not an oficial SDL2 headers for Free Pascal, or it's not been maintained.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7