- Texture my_sub_image(const Rect rect) {
- GLuint subId;
- glGenTextures(1, &subId);
- // Binden den Zieltextur
- glBindTexture(GL_TEXTURE_2D, subId);
- // Parameter der Zieltextur
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
- glTexImage2D(GL_TEXTURE_2D, 0, this._format, rect.width, rect.height, 0,
- this._format, GL_UNSIGNED_BYTE, null);
- // Quelltextur binden
- this.bind();
- // Quelltextur zeichnen
- glBegin(GL_QUADS);
- // top left
- glTexCoord2i(0, 0);
- glVertex2f(0, 0);
- // bottom left
- glTexCoord2i(0, 1);
- glVertex2f(0, rect.height);
- // bottom right
- glTexCoord2i(1, 1);
- glVertex2f(rect.width, rect.height);
- // top right
- glTexCoord2i(1, 0);
- glVertex2f(rect.width, 0);
- glEnd();
- // Zieltextur binden
- glBindTexture(GL_TEXTURE_2D, subId);
- // kopieren
- glCopyTexSubImage2D(
- GL_TEXTURE_2D,
- 0,
- rect.x, rect.y,
- 0, 0,
- rect.width, rect.height
- );
- Texture sub = new Texture();
- sub.setId(subId);
- return sub;
- }