Graphics Example with Simulator for PC

Post Reply
Iulius
Posts: 16
Joined: Sun Feb 10, 2019 3:36 am
languages_spoken: english, german
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 2 times
Contact:

Graphics Example with Simulator for PC

Unread post by Iulius » Sun Feb 10, 2019 4:01 am

Hi,

i just started with the Go 3 days ago, so nothing too special for you guys maybe,
but as i haven't found anything comparable, i will share my little project.

What it includes:
- .ino stub to call the functions inside game.h/cpp for Arduino studio
- wrappers for PC compilation (i did with Visual Studio 2017 community)

What the GO Code does:
- a tile based background
- a objectlist holding different sprites
- a displaylist drawing sprites with priority
- player sprite to move around
- 40 testsprites rapidly moving around
- every size is configurable
- redraw is only done for tiles where sprites are in
- it runs at 240*240 with 41 sprites nearly at 60 Hz
- game has exact timing, so it reaches the FPS/Hz you want if if the GO can do it. you can set to any HZ as you like
- does NOT require a backbuffer for drawing -> a lot less ram required
---> i am preparing for a gauntlet/diablo like game, so the code it probably not useful for any game type.

What the PC Code does:
- uses exact same code (no changes) in a PC program
- wrapper for functions i need(!)
- it's nowhere to complete, probably not even 5% of the library functions are available
BUT:
- it can draw a pixel image based on drawBitmap calls from the GO code
- prints are done using console writes
- inputs are done using WSAD(Keypad) and KL(A+B)
- it's really fast: compile is below 1 second
- as FPS/Hz are timed, it runs at same FPS/Hz as the GO, but you can unlock it if required (e.g. i reach ~600 Hz if unlocked)
- you can easily debug!
----> that's the main reason i've done that

Attention: due to the "creative" way of drawing the image inside a console window, it may hang if you place the mouse over the pixel image.
Just don't do it....


You can download the small .zip from my webpage:
http://www.gp-rc.de/OdroidGo/simplemove.zip

Please tell me what you think.

Regards

User avatar
mad_ady
Posts: 6676
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 194 times
Been thanked: 148 times
Contact:

Re: Graphics Example with Simulator for PC

Unread post by mad_ady » Sun Feb 10, 2019 4:04 am

Sounds like a great project! Keep it up! :)

JT Cook
Posts: 12
Joined: Tue Dec 25, 2018 6:40 am
languages_spoken: english
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 0
Contact:

Re: Graphics Example with Simulator for PC

Unread post by JT Cook » Wed Feb 13, 2019 8:23 am

Very nice, I am working on something similar where I am using Tiny C Compiler and SDL as the simulator on PC and then dump the main code back into Adruino Studio to send to the Go. On mine I have a 256x192 frame buffer that I draw to then send to LCD, it is a little slower though since it updates that whole space at once.

Iulius
Posts: 16
Joined: Sun Feb 10, 2019 3:36 am
languages_spoken: english, german
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Graphics Example with Simulator for PC

Unread post by Iulius » Sat Feb 16, 2019 12:57 am

just in case somebody is using my lib:

there are currently some bugs inside the code(even in the display library!), that i could manage to get out.

As i'm already developing my game with it, it's not that easy to seperate, but i can upload my prototype of the game as example if somebody wants.

JT Cook
Posts: 12
Joined: Tue Dec 25, 2018 6:40 am
languages_spoken: english
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 0
Contact:

Re: Graphics Example with Simulator for PC

Unread post by JT Cook » Sun Feb 17, 2019 1:50 pm

When you say you found bugs in the display library are you talking about the library for Odroid Go for Arduino, or in your own code? Also if it is in the library, what bugs did you find and correct?

Iulius
Posts: 16
Joined: Sun Feb 10, 2019 3:36 am
languages_spoken: english, german
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Graphics Example with Simulator for PC

Unread post by Iulius » Sun Feb 17, 2019 8:12 pm

official library Odroid Go for Arduin, Display.cpp

void ILI9341::pushRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h,uint16_t *data)

This function is not working correct, it transmits the wrong color information to the screen.
The upper and lower byte of the 16bit word need to be swapped before spi.writebytes to have the correct color.
At least if you use the color565 function of the same lib to get the 16 bit color out of rgb values.

There is also no reason to split the transmit to 32 bytes packets, it just slows it down.
Maybe there is a upper limit, but i havent found it yet and did updates of >1000bytes.

JT Cook
Posts: 12
Joined: Tue Dec 25, 2018 6:40 am
languages_spoken: english
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 0
Contact:

Re: Graphics Example with Simulator for PC

Unread post by JT Cook » Mon Feb 18, 2019 5:21 am

Ha, this is exactly what I was using to draw the frame buffer to the screen and ran into issues with colors. I was puzzled when the documentation for drawing the colors did not match up to how I was building a color so I would so I ended up calculating color as such:

color_palette[n]=red<<3 | blue<<8 | ((green&0x3)<<14) | ((green&0x1C)>>2);

I never bothered to look at the function but that is an interesting find about it breaking it up into 32 byte chunks, when I get some time I will have to try it with my code to see if there are any issues blasting near a full screen (256x192). I see that SPI.write16() is there REM'd out, so I am wondering if this would fix the color issue (as well as include a slight speed up, not sure if there is more less overhead with SPI.write16 vs 2 SPI.writeByte).

Iulius
Posts: 16
Joined: Sun Feb 10, 2019 3:36 am
languages_spoken: english, german
ODROIDs: Odroid Go
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Graphics Example with Simulator for PC

Unread post by Iulius » Mon Feb 18, 2019 2:03 pm

if you want, you can use my modified code, it's working with the original rgb function (which make it easier to use common tools when loading images)
and faster. You have to test if it works for a full image.
I'm not sure how this copy array will work with full image in terms of memory usage.
At least it's not leaking, but i'm unsure what it costs, as i draw maximum of 25*25 at a time.

Code: Select all

void ILI9341::pushColors(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *data, uint16_t len) {
  spi_begin();

  CS_L;
  
  setAddrWindow(x0, y0, x1, y1);

  uint8_t copy[len * 2];
  for (int i = 0; i < len; i++)
  {
	copy[i * 2]     = (*(data + i)) >> 8;
	copy[i * 2 + 1] = (*(data + i)) & 0xFF;
  }

  SPI.writeBytes(copy, len * 2);
  
  CS_H;

  spi_end();
}

Post Reply

Return to “Arduino Coding Camp”

Who is online

Users browsing this forum: No registered users and 1 guest