glTexImage2D mit OpenGL

ayloedxa

Grünschnabel
Hallo,

ich benutze glTexImage2D um die Textur für meine Fläche im Programm zu füllen.

Diese benötigt folgende Parameter:

GLenum target,
GLint level,
GLint internalformat,
GLsizei width, (Mach ich mit Image.getWidth())
GLsizei height, (s.o.)
GLint border,
GLenum format, (1. Problem)
GLenum type, (2. Problem)
const GLvoid *pixels (3. Problem, das Große)

1. Als Format benutze ich GL_RGBA. macht es einen großen Unterschied welches ich benutze? Das Bild hat keine Transparenz, ist das A(lpha) also überflüssig oder gar verboten?
2. Als type nehme ich GL_UNSIGNED_BYTE, welches steht sonst noch zur Frage (mit s.u.)
3. So kommen wir zum Hauptproblem:
Hier muss ich eine byte-Array angeben, der die 2-4 Werte (1. Problem) aller Pixel enthält? WIE mache ich das? Hab schon das ganze Internet danach abgesucht..?
Kann mir da bitte einer helfen?


Zusatz: ist folgende Aussage wahr?
Ein Bild besteht aus vielen Pixeln.
Jedes Pixel hat einen Rot, einen Grün, einen Blau und einen Alpha(Transparenz)-Wert.
Zusatz: Was ist ein Texel?
 
public void handlesinglepixel(int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
// Deal with the pixel as necessary...
}

public int[] handlepixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return null;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return null;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
handlesinglepixel(x + i, y + j, pixels[j * w + i]);
}
}
return pixels;
}


Das hab ich wo aufgeschanppt...
Da ist wohl etwas falsch, denn so machts keinen Sinn?
Findet wer den Fehler?
 
Zurück