0 Members and 1 Guest are viewing this topic.

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.

It would also be cool to have some kind of overridable setPixel function. That way you can make simple pixel shaders run

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; } } } }

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.Code: [Select]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

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.

--- 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.

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.

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.

FacebookandTwitterFollow @Codewalr_us