+-Discord Shoutbox


Alternatively, join us on Discord directly.
You can help CodeWalrus stay online by donating here.

Graphics and other system routines

Started by DarkestEx, October 19, 2015, 10:31:05 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DarkestEx

Quote from: Streetwalrus on October 21, 2015, 01:59:46 PM
The copyright notice must be distributed with the binaries. That means you can put a credits screen, have it in a readme or even on a flier that comes with the console.
Yea, still I don't want to credit them. We aren't using foreign code so far and I don't want to start it. I will just rewrite it.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Snektron

It would also be cool to have some kind of overridable setPixel function. That way you can make simple pixel shaders run :)
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


DarkestEx

Quote from: Cumred_Snektron on October 21, 2015, 02:35:41 PM
It would also be cool to have some kind of overridable setPixel function. That way you can make simple pixel shaders run :)
How do you mean?
Also all graphic functions are drawing directly to the buffer not using the setPixel at all for speed.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Snektron

Well, you can make an inline setPixel function for simplicity's sake, right? :)
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


adekto

the pixel comand is in there and used by some of my code, so you can use it
i think you can also acces the hole buffer if you want, not sure how thoug ( you prefer a getpixel or specific regions?)

Adriweb

  • Calculators owned: TI-Nspire CX CAS, TI-Nspire CX, TI-Nspire CAS (x3), TI-Nspire (x2), TI-Nspire CM-C CAS, TI-Nspire CAS+, TI-80, TI-82 Stats.fr, TI-82 Plus, TI-83 Plus, TI-83 Plus.fr USB, TI-84+, TI-84+ Pocket SE, TI-84+ C Silver Edition, TI-84 Plus CE, TI-89 Titanium, TI-86, TI-Voyage 200, TI-Collège Plus, TI-Collège Plus Solaire, 3 HP, some Casios
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Snektron

I've made a ploygon fill algoritm. the speed is okay i think, but it still requires a sort for every horizontal line of pixels. I've used bubble sort for now but its easily changable.


public void polygon(int... points)
{
final int accuracy = 8;

if (points.length % 2 != 0 || points.length < 6)
return;

int[] get = new int[points.length / 2 * 5];
int getn = 0;
int [] xpt = new int[points.length / 2];
int xptn;

int pymax = 0, pymin = height-1;

for (int i=0; i<points.length; i+=2)
{
int x0 = points[i];
int y0 = points[i+1];
int x1 = points[(i+2)%points.length];
int y1 = points[(i+3)%points.length];

if (y0 > y1)
{
get[getn] = y1;
get[getn+1] = y0;
get[getn+2] = (x0-x1<<accuracy)/(y0-y1); // inverse slope
get[getn+3] = x0;
get[getn+4] = x0;
getn += 5;
}else if (y0 != y1)
{
get[getn] = y0;
get[getn+1] = y1;
get[getn+2] = (x1-x0<<accuracy)/(y1-y0); // inverse slope
get[getn+3] = x1;
get[getn+4] = x0;
getn += 5;
}

pymax = Math.max(y0, pymax);
pymin = Math.min(y0, pymin);
}

for (int scan=pymin+1; scan <= pymax; scan++)
{
xptn = 0;
for (int i=0; i<getn; i+=5)
if (scan > get[i] && scan <= get[i+1])
xpt[xptn++] = ((scan - get[i+1])*get[i+2]>>accuracy) + get[i+3];

bubbleSort(xpt, xptn);

for (int i=0; i<xptn-1; i+=2)
for (int x = xpt[i]; x < xpt[i+1]; x++)
setPixel(x, scan);
}
}

public void bubbleSort(int[] array, int n)
{
    boolean swapped = true;
    int j = 0;
    int tmp;
    while (swapped)
    {
    swapped = false;
    j++;
    for (int i = 0; i < n-j; i++)
    {
    if (array[i] > array[i+1])
    {
    tmp = array[i];
    array[i] = array[i+1];
    array[i+1] = tmp;
    swapped = true;
    }
    }
    }
}


note: "int... points" is anotherway of writing "int[] points" in java. The difference is you can supply the arguments without making them an array first, ie polygon(0, 10, 10, 10, 10, 0); which is the same as polygon(new int[]{0, 10, 10, 10, 10, 0});  ;)

Since it uses ints only and a slope is a value which usually is a floating point number ive mutiplied it with a number (the accuracy constant). To save on precious cpu cycles i've used shift instead of multiply/divide
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


DarkestEx

Quote from: Cumred_Snektron on October 21, 2015, 06:09:29 PM
I've made a ploygon fill algoritm. the speed is okay i think, but it still requires a sort for every horizontal line of pixels. I've used bubble sort for now but its easily changable.


public void polygon(int... points)
{
final int accuracy = 8;

if (points.length % 2 != 0 || points.length < 6)
return;

int[] get = new int[points.length / 2 * 5];
int getn = 0;
int [] xpt = new int[points.length / 2];
int xptn;

int pymax = 0, pymin = height-1;

for (int i=0; i<points.length; i+=2)
{
int x0 = points[i];
int y0 = points[i+1];
int x1 = points[(i+2)%points.length];
int y1 = points[(i+3)%points.length];

if (y0 > y1)
{
get[getn] = y1;
get[getn+1] = y0;
get[getn+2] = (x0-x1<<accuracy)/(y0-y1); // inverse slope
get[getn+3] = x0;
get[getn+4] = x0;
getn += 5;
}else if (y0 != y1)
{
get[getn] = y0;
get[getn+1] = y1;
get[getn+2] = (x1-x0<<accuracy)/(y1-y0); // inverse slope
get[getn+3] = x1;
get[getn+4] = x0;
getn += 5;
}

pymax = Math.max(y0, pymax);
pymin = Math.min(y0, pymin);
}

for (int scan=pymin+1; scan <= pymax; scan++)
{
xptn = 0;
for (int i=0; i<getn; i+=5)
if (scan > get[i] && scan <= get[i+1])
xpt[xptn++] = ((scan - get[i+1])*get[i+2]>>accuracy) + get[i+3];

bubbleSort(xpt, xptn);

for (int i=0; i<xptn-1; i+=2)
for (int x = xpt[i]; x < xpt[i+1]; x++)
setPixel(x, scan);
}
}

public void bubbleSort(int[] array, int n)
{
    boolean swapped = true;
    int j = 0;
    int tmp;
    while (swapped)
    {
    swapped = false;
    j++;
    for (int i = 0; i < n-j; i++)
    {
    if (array[i] > array[i+1])
    {
    tmp = array[i];
    array[i] = array[i+1];
    array[i+1] = tmp;
    swapped = true;
    }
    }
    }
}


note: "int... points" is anotherway of writing "int[] points" in java. The difference is you can supply the arguments without making them an array first, ie polygon(0, 10, 10, 10, 10, 0); which is the same as polygon(new int[]{0, 10, 10, 10, 10, 0});  ;)

Since it uses ints only and a slope is a value which usually is a floating point number ive mutiplied it with a number (the accuracy constant). To save on precious cpu cycles i've used shift instead of multiply/divide
Nice :)

This is the final color palette in case somebody hasn't seen it yet:
http://docs.ninjabyte.eu/microcat/global_palette.html
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

DJ Omnimaga

Quote from: DarkestEx on October 21, 2015, 01:45:10 PM
Quote from: Streetwalrus
--- Quote from: DarkestEx on Today at 03:30:03 pm ---I really don't like the licence of the code. It requires us to include a copyright. I think its better to use the functions provided earlier in this topic.

--- End quote ---
That's just the BSD license, the "copyright notice" is only a request for credits.
Sure, but i don't like and can't include the licence into the binary image. I want to have as much of the code written by us or people interested in the project as possible. I don't like reusing others code when not required. In this case, as we have most functions that we will use provided by either the great people here, written ourselves or adapted from MIT code, I think we will just rewirite the external code.
I think my main gripe with using code that requires copyrights like this would be the fact the readme or console is littered with watermarks. Imagine if everytime you start the console you were forced to display some splash screen with the company logo of the people who wrote the code or something (like when starting a Game Maker game)

It's fine if the only place where you are forced to put credits in is the readme or credits screen, though, since those aren't intrusive. But I guess using your own code would be better since it makes it easier to sell the console.
  • Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10, HP Prime, fx 1.0 Plus, fx-7400G Plus, fx-9750G Plus, fx-9860G, HP 39gII
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite

Streetwalrus

These licenses are made exactly so that you can freely reuse the code for anything. I think it's pretty fair that the author is asking for credits.

DJ Omnimaga

Yeah I know. I am mostly talking about licenses that requires using anything that looks like a watermark or advertising. Imagine playing First Fantasy Microcat with ads plastered everywhere O.O
  • Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10, HP Prime, fx 1.0 Plus, fx-7400G Plus, fx-9750G Plus, fx-9860G, HP 39gII
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite

Streetwalrus

Lol that's abusive, no one would want to use code under such a license.

DarkestEx

Quote from: Streetwalrus on October 23, 2015, 06:34:38 AM
These licenses are made exactly so that you can freely reuse the code for anything. I think it's pretty fair that the author is asking for credits.
Sure but I don't want to use such code when not absolutely required.
That's my final word on this.
I really don't want to plaster my binary files with copyright notices for single functions.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

semiprocoder

November 13, 2015, 12:22:13 AM #43 Last Edit: November 13, 2015, 12:26:25 AM by semiprocoder
wait are you still suporting 16 bit color mode?
Also do you want a pure triangle draw code, because I could easily make one, as I made one in lua that I deleted, as it was(a bit) slower than filling polygons,at least on computer. However, it only sorts the points. Also, lua uses decimals, while I would use integers in the c code for this.
  • Calculators owned: ti nspire, ti 84 plus se
My cemetech username is awesommee333.

DarkestEx

Quote from: semiprocoder on November 13, 2015, 12:22:13 AM
wait are you still suporting 16 bit color mode?
Also do you want a pure triangle draw code, because I could easily make one, as I made one in lua that I deleted, as it was(a bit) slower than filling polygons,at least on computer. However, it only sorts the points. Also, lua uses decimals, while I would use integers in the c code for this.
No true 16 bit colors aren't supported anymore. Though you can cheat by using the 39 dynamic palette colors that you can assign any 16 bit color to. You can use these dynamic colors everywhere from sprites to all drawing functions.

About the triangle code, I would love to have yours if you post it here. I am glad about any graphic function that is useful in game making and has no requirement for floating point :)
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Powered by EzPortal