got textures with alpha/rgb working with gl.. changed to ARGB instead of

RGBA for constant
This commit is contained in:
benfry
2004-12-21 05:20:30 +00:00
parent 1b04142843
commit 7fcd55fa5c
10 changed files with 94 additions and 52 deletions
+2 -1
View File
@@ -374,6 +374,7 @@ public class PdeRuntime implements PdeMessageConsumer {
// this is PApplet sending a message (via System.out.println)
// that signals that the applet has been quit.
if (s.indexOf(PApplet.EXTERNAL_QUIT) == 0) {
System.out.println("external: quit");
editor.doClose();
return;
}
@@ -386,7 +387,7 @@ public class PdeRuntime implements PdeMessageConsumer {
int left = Integer.parseInt(nums.substring(0, space));
int top = Integer.parseInt(nums.substring(space + 1));
editor.appletLocation = new Point(left, top);
//System.out.println("wanna move to " + left + " " + top);
System.out.println("external: move to " + left + " " + top);
return;
}
+4 -4
View File
@@ -1373,7 +1373,7 @@ public class PApplet extends Applet
if (invisible_cursor == null) {
//invisible_cursor = new PImage(new int[32*32], 32, 32, RGBA);
invisible_cursor = new PImage(new int[16*16], 16, 16, RGBA);
invisible_cursor = new PImage(new int[16*16], 16, 16, ARGB);
}
// was formerly 16x16, but the 0x0 was added by jdf as a fix
// for macosx, which didn't wasn't honoring the invisible cursor
@@ -2027,7 +2027,7 @@ public class PApplet extends Applet
// since transparency is often at corners, hopefully this
// will find a non-transparent pixel quickly and exit
if ((jpixels[i] & 0xff000000) != 0xff000000) {
return new PImage(jpixels, jwidth, jheight, RGBA);
return new PImage(jpixels, jwidth, jheight, ARGB);
//format = RGBA;
//break;
}
@@ -2059,7 +2059,7 @@ public class PApplet extends Applet
// setup new image object
PImage img = new PImage(w,h);
img.format = (hasAlpha ? RGBA : RGB);
img.format = (hasAlpha ? ARGB : RGB);
// targa's are written upside down, so we need to parse it in reverse
int index = (h-1) * w;
@@ -4101,7 +4101,7 @@ public class PApplet extends Applet
Frame frame = new Frame();
frame.setResizable(false); // remove the grow box
frame.pack(); // get insets. get more.
frame.show(); // gl hack
//frame.show(); // gl hack
Class c = Class.forName(name);
PApplet applet = (PApplet) c.newInstance();
applet.frame = frame;
+1 -1
View File
@@ -68,7 +68,7 @@ public interface PConstants {
// for colors and/or images
static final int RGB = 1; // image & color
static final int RGBA = 2; // image
static final int ARGB = 2; // image
static final int HSB = 3; // color
static final int ALPHA = 4; // image
+5 -3
View File
@@ -195,9 +195,11 @@ public class PFont implements PConstants {
//images[i].pixels[y * twidth + x] = valu;
images[i].pixels[y * twidth + x] =
(valu << 24) | 0xFFFFFF;
//0xFFFFFF00 | valu;
//(valu << 24) | (valu << 16) | (valu << 8) | valu;
valu;
//(valu << 24) | 0xFFFFFF; // windows
//0xFFFFFF00 | valu; // macosx
//(valu << 24) | (valu << 16) | (valu << 8) | valu;
//0x8040ff40;
//(valu << 24) | (valu << 16) | (valu << 8) | valu;
//System.out.print((images[i].pixels[y*64+x] > 128) ? "*" : ".");
+5 -5
View File
@@ -1855,7 +1855,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
private void thick_point(float x, float y, float z, // note floats
float r, float g, float b, float a) {
spolygon.reset(4);
spolygon.interpRGBA = false; // no changes for vertices of a point
spolygon.interpARGB = false; // no changes for vertices of a point
float strokeWidth2 = strokeWeight/2.0f;
@@ -1915,7 +1915,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
float r1, float g1, float b1, float a1,
float ox2, float oy2,
float r2, float g2, float b2, float a2) {
spolygon.interpRGBA = (r1 != r2) || (g1 != g2) || (b1 != b2) || (a1 != a2);
spolygon.interpARGB = (r1 != r2) || (g1 != g2) || (b1 != b2) || (a1 != a2);
spolygon.interpZ = false;
float dX = ox2-ox1 + EPSILON;
@@ -1974,7 +1974,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
float r1, float g1, float b1,
float x2, float y2, float z2,
float r2, float g2, float b2) {
spolygon.interpRGBA = (r1 != r2) || (g1 != g2) || (b1 != b2);
spolygon.interpARGB = (r1 != r2) || (g1 != g2) || (b1 != b2);
spolygon.interpZ = true;
float ox1 = x1; float oy1 = y1; float oz1 = z1;
@@ -2465,7 +2465,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
int source = iy1 * image.width + ix1;
int target = sy1 * width;
if (image.format == RGBA) {
if (image.format == ARGB) {
for (int y = sy1; y < sy2; y++) {
int tx = 0;
@@ -4893,7 +4893,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
"as your application");
return;
}
if ((image.format != RGB) && (image.format != RGBA)) {
if ((image.format != RGB) && (image.format != ARGB)) {
System.err.println("background images should be RGB or RGBA");
return;
}
+47 -17
View File
@@ -70,7 +70,7 @@ import java.io.*;
public class PImage implements PConstants, Cloneable {
/**
* Format for this image, one of RGB, RGBA or ALPHA.
* Format for this image, one of RGB, ARGB or ALPHA.
* note that RGB images still require 0xff in the high byte
* because of how they'll be manipulated by other functions
*/
@@ -121,7 +121,7 @@ public class PImage implements PConstants, Cloneable {
*/
public PImage(int width, int height) {
init(width, height, RGB);
//this(new int[width * height], width, height, RGBA);
//this(new int[width * height], width, height, ARGB);
// toxi: is it maybe better to init the image with max alpha enabled?
//for(int i=0; i<pixels.length; i++) pixels[i]=0xffffffff;
// fry: i'm opting for the full transparent image, which is how
@@ -160,6 +160,7 @@ public class PImage implements PConstants, Cloneable {
int width2 = (int) Math.pow(2, Math.ceil(Math.log(width) / Math.log(2)));
int height2 = (int) Math.pow(2, Math.ceil(Math.log(height) / Math.log(2)));
/*
if ((width2 == width) && (height2 == height)) {
// image can be used by itself as the texture image
tpixels = pixels;
@@ -167,24 +168,53 @@ public class PImage implements PConstants, Cloneable {
theight = height;
} else {
if ((width2 > twidth) || (height2 > theight)) {
// either twidth/theight are zero, or size has changed
tpixels = null;
}
if (tpixels == null) {
twidth = width2;
theight = height2;
tpixels = new int[twidth * theight];
}
// copy image data into the texture
int p = 0;
int t = 0;
for (int y = 0; y < height; y++) {
*/
if ((width2 > twidth) || (height2 > theight)) {
// either twidth/theight are zero, or size has changed
tpixels = null;
}
if (tpixels == null) {
twidth = width2;
theight = height2;
tpixels = new int[twidth * theight];
}
// copy image data into the texture
int p = 0;
int t = 0;
for (int y = 0; y < height; y++) {
switch (format) {
case ALPHA:
for (int x = 0; x < width; x++) {
tpixels[t++] = 0xFFFFFF00 | pixels[p++];
}
t += twidth - width;
break;
case RGB:
for (int x = 0; x < width; x++) {
int pixel = pixels[p++];
tpixels[t++] = (pixel << 8) | 0xff;
}
t += twidth - width;
/*
System.arraycopy(pixels, p, tpixels, t, width);
p += width;
t += twidth;
*/
break;
case ARGB:
for (int x = 0; x < width; x++) {
int pixel = pixels[p++];
//tpixels[t++] = 0x80808080;
tpixels[t++] = (pixel << 8) | ((pixel >> 24) & 0xff);
//tpixels[t++] = 0xFFFFFF00 | pixels[p++];
}
t += twidth - width;
break;
}
}
//}
}
@@ -233,7 +263,7 @@ public class PImage implements PConstants, Cloneable {
(image.pixels[i] & 0xffffff);
}
/*
if (highbits) { // grab alpha from the high 8 bits (RGBA style)
if (highbits) { // grab alpha from the high 8 bits (ARGB style)
for (int i = 0; i < pixels.length; i++) {
pixels[i] = pixels[i] & 0xffffff | (alpha[i] & 0xff000000);
}
@@ -243,7 +273,7 @@ public class PImage implements PConstants, Cloneable {
}
}
*/
image.format = RGBA;
image.format = ARGB;
}
+19 -19
View File
@@ -49,7 +49,7 @@ public class PPolygon implements PConstants {
boolean interpX;
boolean interpZ;
boolean interpUV; // is this necessary? could just check timage != null
boolean interpRGBA;
boolean interpARGB;
int rgba;
int r2, g2, b2, a2, a2orig;
@@ -108,7 +108,7 @@ public class PPolygon implements PConstants {
interpX = true;
interpZ = true;
interpUV = false;
interpRGBA = true;
interpARGB = true;
timage = null;
}
@@ -190,7 +190,7 @@ public class PPolygon implements PConstants {
width1 = width - 1;
height1 = height - 1;
if (!interpRGBA) {
if (!interpARGB) {
r2 = (int) (vertices[0][R] * 255);
g2 = (int) (vertices[0][G] * 255);
b2 = (int) (vertices[0][B] * 255);
@@ -434,9 +434,9 @@ public class PPolygon implements PConstants {
px0 = (pixel00*tuf + pixel10*tuf1) >> 8;
px1 = (pixel01*tuf + pixel11*tuf1) >> 8;
ta = (((px0*tvf + px1*tvf1) >> 8) *
(interpRGBA ? ((int) (sp[A]*255)) : a2orig)) >> 8;
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
} else if (tformat == RGBA) {
} else if (tformat == ARGB) {
p00 = (pixel00 >> 24) & 0xff;
p01 = (pixel01 >> 24) & 0xff;
p10 = (pixel10 >> 24) & 0xff;
@@ -445,13 +445,13 @@ public class PPolygon implements PConstants {
px0 = (p00*tuf + p10*tuf1) >> 8;
px1 = (p01*tuf + p11*tuf1) >> 8;
ta = (((px0*tvf + px1*tvf1) >> 8) *
(interpRGBA ? ((int) (sp[A]*255)) : a2orig)) >> 8;
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
} else { // RGB image, no alpha
ta = interpRGBA ? ((int) (sp[A]*255)) : a2orig;
ta = interpARGB ? ((int) (sp[A]*255)) : a2orig;
}
if ((tformat == RGB) || (tformat == RGBA)) {
if ((tformat == RGB) || (tformat == ARGB)) {
p00 = (pixel00 >> 16) & 0xff; // red
p01 = (pixel01 >> 16) & 0xff;
p10 = (pixel10 >> 16) & 0xff;
@@ -460,7 +460,7 @@ public class PPolygon implements PConstants {
px0 = (p00*tuf + p10*tuf1) >> 8;
px1 = (p01*tuf + p11*tuf1) >> 8;
tr = (((px0*tvf + px1*tvf1) >> 8) *
(interpRGBA ? ((int) sp[R]*255) : r2)) >> 8;
(interpARGB ? ((int) sp[R]*255) : r2)) >> 8;
p00 = (pixel00 >> 8) & 0xff; // green
@@ -471,7 +471,7 @@ public class PPolygon implements PConstants {
px0 = (p00*tuf + p10*tuf1) >> 8;
px1 = (p01*tuf + p11*tuf1) >> 8;
tg = (((px0*tvf + px1*tvf1) >> 8) *
(interpRGBA ? ((int) sp[G]*255) : g2)) >> 8;
(interpARGB ? ((int) sp[G]*255) : g2)) >> 8;
p00 = pixel00 & 0xff; // blue
@@ -482,10 +482,10 @@ public class PPolygon implements PConstants {
px0 = (p00*tuf + p10*tuf1) >> 8;
px1 = (p01*tuf + p11*tuf1) >> 8;
tb = (((px0*tvf + px1*tvf1) >> 8) *
(interpRGBA ? ((int) sp[B]*255) : b2)) >> 8;
(interpARGB ? ((int) sp[B]*255) : b2)) >> 8;
} else { // alpha image, only use current fill color
if (interpRGBA) {
if (interpARGB) {
tr = (int) (sp[R] * 255);
tg = (int) (sp[G] * 255);
tb = (int) (sp[B] * 255);
@@ -511,7 +511,7 @@ public class PPolygon implements PConstants {
if (tformat == ALPHA) {
ta = tpixel;
if (interpRGBA) {
if (interpARGB) {
tr = (int) sp[R]*255;
tg = (int) sp[G]*255;
tb = (int) sp[B]*255;
@@ -526,10 +526,10 @@ public class PPolygon implements PConstants {
ta = (a2orig * ta) >> 8;
}
} else { // RGB or RGBA
} else { // RGB or ARGB
ta = (tformat == RGB) ? 255 : (tpixel >> 24) & 0xff;
if (interpRGBA) {
if (interpARGB) {
tr = (((int) sp[R]*255) * ((tpixel >> 16) & 0xff)) >> 8;
tg = (((int) sp[G]*255) * ((tpixel >> 8) & 0xff)) >> 8;
tb = (((int) sp[B]*255) * ((tpixel) & 0xff)) >> 8;
@@ -566,7 +566,7 @@ public class PPolygon implements PConstants {
} else { // no image applied
int weight = smoothing ? coverage(x) : 255;
if (interpRGBA) {
if (interpARGB) {
r2 = (int) (sp[R] * 255);
g2 = (int) (sp[G] * 255);
b2 = (int) (sp[B] * 255);
@@ -652,7 +652,7 @@ public class PPolygon implements PConstants {
p[Z] = p1[Z] + dp[Z] * fraction;
}
if (interpRGBA) {
if (interpARGB) {
dp[R] = (p2[R] - p1[R]) / delta;
dp[G] = (p2[G] - p1[G]) / delta;
dp[B] = (p2[B] - p1[B]) / delta;
@@ -699,7 +699,7 @@ public class PPolygon implements PConstants {
p[Z] = p1[Z] + dp[Z] * fraction;
}
if (interpRGBA) {
if (interpARGB) {
dp[R] = (p2[R] - p1[R]) / delta;
dp[G] = (p2[G] - p1[G]) / delta;
dp[B] = (p2[B] - p1[B]) / delta;
@@ -736,7 +736,7 @@ public class PPolygon implements PConstants {
if (interpX) p[X] += dp[X];
if (interpZ) p[Z] += dp[Z];
if (interpRGBA) {
if (interpARGB) {
p[R] += dp[R];
p[G] += dp[G];
p[B] += dp[B];
+1 -1
View File
@@ -348,7 +348,7 @@ public class PTriangle implements PConstants
F_TEX_HEIGHT = TEX_HEIGHT-1;
INTERPOLATE_UV = true;
if (image.format == RGBA) {
if (image.format == ARGB) {
m_drawFlags|=R_TEXTURE32;
} else if (image.format == RGB) {
m_drawFlags|=R_TEXTURE24;
+8 -1
View File
@@ -10,6 +10,7 @@ X add TRIANGLE_FAN
X eyeX, eyeY etc have been renamed cameraX/Y/Z, and cameraNear/Far
X modify targa and tiff writing routines to break into header writing
X writeTIFF, writeHeaderTIFF, writeTGA, writeHeaderTGA
X MAJOR CHANGE: RGBA becomes ARGB for accuracy
opengl
X why is the thing hanging until 'stop' is hit?
@@ -24,7 +25,13 @@ X INVALID_OPERATION after drawing lines for cube
X fix noLoop bug
X remove errors when drawing textures
_ fix the usual nasty texture bug found in every acu app
_ figure out min/max texture sizes when binding to avoid problems
_ fix non-bound textures from mangling everything else
_ fix enable/disable textures for some objects
_ fix endian ordering issues so that things work properly
_ make play button un-highlight with opengl
_ also make window move messages work properly
_ can ALPHA fonts work using the other replace modes
_ resolve ARGB versus RGBA versus just A issues for fonts
_ make sure that current scenario works identically on mac
_ if so, just switch the image code to expect alpha in the high bits
+2
View File
@@ -18,6 +18,8 @@ _ may need a progress bar for "save as"
_ or just the file copy function in general
_ since it may take a long time (i.e. 1000s of screen grabs)
_ opening up sketch folder may be extremely slow
_ preproc: making all functions public that have no specifier
_ this will make draw() etc all much easier
_ as well as the library events