Author Topic: nSDL 1.1.1 Anniversary Edition—The Ultimate TI-Nspire Graphics Library  (Read 140626 times)

0 Members and 2 Guests are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #315 on: January 11, 2013, 02:48:05 am »
EDIT: Maybe you should initialize SDL as 8 bpp? nSDL handles 8 bpp on CX, and as you're only dealing with 8 bpp stuff it would maybe be easier to concentrate only on one bit depth?

Yeah, I can try that, but I don't know how to :/

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #316 on: January 11, 2013, 03:41:03 am »
Just initialize SDL with a 8bpp bit depth, i.e. in the SDL_SetVideoMode instead of is_cx?16:8, just use 8.

But quite sure the color issue is just because of  some wrong SDL_PixelFormat passed to SDL_MapRGB (first parameter) or something. Your pixel access function should handle different bit depths automatically, and the only way to have strange results is by passing a wrong color.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #317 on: January 11, 2013, 09:38:11 am »
It's kinda strange in fact. If I try to just blit my gif image (exactly the one I attached above) to the screen it's ok :



But if I access it with my getPixel function I get that with 16 bpp :



And that with 8 bpp :



That's kinda strange ???

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #318 on: January 11, 2013, 10:13:19 am »
Attach the whole code here, doesn't matter if it's ugly as hell. It's difficult to fix without any code. I'm pretty sure it's either your setpixel function that doesn't work, or that the color value that you're passing to the function isn't of the same bit depth as the surface on which you're drawing.
« Last Edit: January 11, 2013, 11:54:06 am by hoffa »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #319 on: January 12, 2013, 01:04:09 pm »
I attached all that is needed to compile and test the program. But please, you who are watching this topic, don't use any of the code I posted, it's all full of unoptimized stuffs.

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #320 on: January 12, 2013, 01:56:15 pm »
I quickly looked at the code.

color is taken from bitmap, which is an 8 bpp surface (the GIF, that is).
You then set color on a 16 bpp surface (the screen variable on a CX)
That must be the problem; you're drawing a 8 bpp color on a 16 bpp surface.
I suggest you to either initialize SDL with 8 bpp, or pass bitmap through SDL_DisplayFormat().
« Last Edit: January 12, 2013, 01:56:53 pm by hoffa »

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #321 on: January 12, 2013, 02:31:42 pm »
8 bpp helps compatibility with Clickpad/Touchpad, although the screen is so bad that the game would hardly be playable anyway on those models, and I'm not convinced that we need much more than 256 colors for a F-Zero game on a platform without hardware acceleration... so I'd suggest using 8 bpp mode as well.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #322 on: January 12, 2013, 03:08:20 pm »
I already attached a pic of the program with SDL initialized in 8bpp mode, it didn't work anymore (green display). Moreover, the use of SDL_DisplayMode(bitmap) takes out all the available memory and throws "SDL : out of memory".
« Last Edit: January 12, 2013, 03:09:19 pm by Matrefeytontias »

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #323 on: January 12, 2013, 06:22:35 pm »
Alrighty a few things here.

1. When compiling your program, use -Wall -Wextra to spot things that could cause issues. For instance, you're freeing tempBitmap and sky but they've never been initialized.

2. Don't do stuff like this: screen->format = SDL_PIXELFORMAT_RGB332;. SDL should take care of the pixel format automatically.

3. Here's why the color was messed up: when you're using 8 bpp depth, each pixel is stored in a single byte. That byte isn't enough to store the RGB value directly, and so a palette is used to map each value to a certain color. I don't know why SDL_image would do it, but seems like the palette isn't the same on bitmap and screen (maybe you used GIMP to save it? Dunno). That's why you need to make them same, by copying bitmap's palette to screen's palette using SDL_SetColors(). Just do SDL_SetColors(screen, bitmap->format->palette->colors, 0, bitmap->format->palette->ncolors) just after loading the GIF (look up the function on google so you understand what you're writing). That way both palettes match, and here's the result:



It sucks at first but that's the way 8-bit displays work.

EDIT: When I saved that GIF again on Paint, it grew to 2.1 MB, but with that one colors were correct without changing the palette at all. What program did you use to save the GIF and how'd you get it down to 800 kB? It might be the program that has a palette completely different from everyone else.

4. SDL_SetColorKey(shipSurface, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0xff, 0, 0xff)); should be SDL_SetColorKey(shipSurface, SDL_SRCCOLORKEY, SDL_MapRGB(shipSurface->format, 0xff, 0, 0xff));, as you're mapping that RGB(255,0,255) using shipSurface's bpp (which might very well be different from that of screen).
« Last Edit: January 12, 2013, 06:33:20 pm by hoffa »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #324 on: January 13, 2013, 01:14:33 pm »
I always use Gimp for image editing (I find it soooooo useful).

Also, thanks a lot, it works ! :)
« Last Edit: January 13, 2013, 01:14:49 pm by Matrefeytontias »

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #325 on: January 17, 2013, 02:54:19 pm »


nSDL 1.1.0 Anniversary Edition is here!

The 23rd of this month it will be one year since the creation of this thread and the beginning of nSDL! :hyper:

Right away, here's the changelog:
  • Added (fastish) nSDL_GetPixel(), nSDL_SetPixel()
  • Added nSDL_EnableRelativePaths()
  • Added nSDL_EnableFontMonospaced()
  • Fixed result from nSDL_GetStringWidth() in some special cases
  • Fixed bug with stuff sometimes not showing up because of bit depth issues
  • nSDL_LoadImage() now always returns a 16-bit surface
  • Removed nSDL_DrawStringInRect(); very little use, complexifies code unnecessarily
  • Removed nSDL_SetFontFlags()
  • Changed nSDL_LoadFont() prototype to nSDL_Font *nSDL_LoadFont(int, Uint8, Uint8, Uint8)
  • More accurate timer
  • Cleaned up a lot of code (aka fixing what's not broken), (e.g. the font system is much simpler and easier to maintain)
  • Smaller static library resulting in smaller executables
  • Apart from nSDL itself, added SDL_image
  • Added sample to build

As usual, the download is available on the nSDL website. For more information about the new function prototypes and whatnot, check the wiki.

As mentioned earlier, this will most probably be the last update before a very long pause! :ninja:

Spoiler For Spoiler:
I'm going backpacking to Australia in early February for half a year. :)
« Last Edit: January 17, 2013, 03:16:33 pm by hoffa »

Offline SpiroH

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +153/-23
    • View Profile
Re: nSDL 1.1.0 Anniversary Edition—The Ultimate TI-Nspire Graphics Library!
« Reply #326 on: January 17, 2013, 04:59:38 pm »
Happy nSpirish-SDL Birthday! Good shot. ;)

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.1.1 Anniversary Edition—The Ultimate TI-Nspire Graphics Library!
« Reply #327 on: January 29, 2013, 03:39:14 pm »
Oh wow, well I'm glad I found out about this before leaving. There was one big issue with 1.1.0; I'll quote:

BTW, about the SDL_GetTicks() issue you mentioned earlier, it was my fault. I had completely forgotten to uncomment a line in nSDL that enabled bus access for the timer, and consequently it worked on the emulator but not one the actual hardware (i.e., it returned always 0). It was extremely dumb and careless from me, but I've updated it now, SDL_GetTicks() should work now (I've tested it on both physical calculators, everything runs smoothly).

Let's just pretend that 1.1.0 never existed. :ninja:

Anyway, updated, download available on the website, you know the drill.

EDIT:

Oh, by the way, I also wrote an online image-to-NTI converter. It does exactly the same thing as the program included in nSDL, except it's faster for massive images and does no formatting whatsoever (which means a smaller source file): http://hoffa.franceserv.fr/nti/
« Last Edit: January 29, 2013, 04:24:46 pm by hoffa »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: nSDL 1.1.1 Anniversary Edition—The Ultimate TI-Nspire Graphics Library!
« Reply #328 on: January 31, 2013, 10:49:53 pm »
What program is this picture?
http://i.imgur.com/ONKjZ.png

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: nSDL 1.1.1 Anniversary Edition—The Ultimate TI-Nspire Graphics Library!
« Reply #329 on: January 31, 2013, 10:51:27 pm »
Oh wow, well I'm glad I found out about this before leaving. There was one big issue with 1.1.0; I'll quote:

BTW, about the SDL_GetTicks() issue you mentioned earlier, it was my fault. I had completely forgotten to uncomment a line in nSDL that enabled bus access for the timer, and consequently it worked on the emulator but not one the actual hardware (i.e., it returned always 0). It was extremely dumb and careless from me, but I've updated it now, SDL_GetTicks() should work now (I've tested it on both physical calculators, everything runs smoothly).

Let's just pretend that 1.1.0 never existed. :ninja:
Woo, glad to here that issue is fixed! I guess I can start a (not so) secret porting project again! ;)
« Last Edit: January 31, 2013, 10:51:44 pm by alberthrocks »
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)