Guten Abend allerseits!
ich habe eine Klasse implementiert (JFrame), welche ein Rechteck und eine Kugel (mit Hilfe von GLUquadric) auf einem GLJPanel darstellt. Das Rechteck wird mit der Textur "stars.bmp" belegt, die Kugel mit der Textur "earth.bmp". Es soll also eine vereinfachte Erde vor einem Sternenhintergrund dargestellt werden. Nun besteht das Problem, dass die Textur der Erde an der vertikalen Achse gespiegelt wird. Afrika befindet sich also westlich von Südamerika (siehe Bild im Anhang).
Die Texturen werden ordnungsgemäß aus den Dateien geladen, die Hintergrundtextur wird richtig dargestellt.
Hier der Quellcode:
Verwendet wird JOGL Version 2.0 und Java 6 Update 21. Als IDE kommt Eclipse 3.5.1. zum Einsatz.
Wenn ich folgende Zeile:
wie folgt abändere
wird die Textur richtig dargestellt, allerdings muss die Erde dann um 270 Grad gedreht werden, da sie sonst auf dem Kopf stünde. Ich nehme aber mal an, dass dies nur eine "Quick and dirty"-Lösung darstellen kann, die Richtung der Normalen der Quadric nach innen zeigen zu lassen. Zumal in allen Code-Beispielen in der Literatur stehts der Parameter GLU_OUTSIDE verwendet wird.
Muss man hierfür eine Änderung an der Texturmatrix vornehmen? (nach Umschalten auf glMatrixMode(GL.GL_TEXTURE); )
Vielen Dank bereits im Voraus!
ich habe eine Klasse implementiert (JFrame), welche ein Rechteck und eine Kugel (mit Hilfe von GLUquadric) auf einem GLJPanel darstellt. Das Rechteck wird mit der Textur "stars.bmp" belegt, die Kugel mit der Textur "earth.bmp". Es soll also eine vereinfachte Erde vor einem Sternenhintergrund dargestellt werden. Nun besteht das Problem, dass die Textur der Erde an der vertikalen Achse gespiegelt wird. Afrika befindet sich also westlich von Südamerika (siehe Bild im Anhang).
Die Texturen werden ordnungsgemäß aus den Dateien geladen, die Hintergrundtextur wird richtig dargestellt.
Hier der Quellcode:
Java:
public class TexturesTestApp extends JFrame implements GLEventListener {
private static final long serialVersionUID = 1L;
private GLProfile _glProfile;
private GLCapabilities _glCaps;
private GLJPanel _panel = null;
private TextureData _earthTextureData = null;
private TextureData _backgroundTextureData = null;
public TexturesTestApp()
{
super();
this.setTitle("Texture Test");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this._glProfile = GLProfile.getDefault();
this._glCaps = new GLCapabilities(this._glProfile);
this._panel = new GLJPanel(this._glCaps);
this._panel.addGLEventListener(this);
this.setSize(600, 600);
this.setLayout(new BorderLayout());
this.getContentPane().add(this._panel, BorderLayout.CENTER);
this.centerWindow();
}
public void centerWindow()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
this.setLocation(
(screenSize.width - frameSize.width) >> 1,
(screenSize.height - frameSize.height) >> 1
);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
TexturesTestApp app = new TexturesTestApp();
app.setVisible(true);
}
}
);
}
@Override
public void display(GLAutoDrawable drawable)
{
try
{
GL2 someGL2 = drawable.getGL().getGL2();
GLU someGLU = GLU.createGLU(someGL2);
someGL2.glClear(
GL.GL_COLOR_BUFFER_BIT |
GL.GL_DEPTH_BUFFER_BIT);
someGL2.glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_DECAL);
Texture texBackground = TextureIO.newTexture(this._backgroundTextureData);
texBackground.enable();
texBackground.bind();
someGL2.glBegin(GL2.GL_QUADS);
TextureCoords coords = texBackground.getImageTexCoords();
someGL2.glTexCoord2f(coords.left(), coords.bottom());
someGL2.glVertex3i(-15, -6, -12);
someGL2.glTexCoord2f(coords.left(), coords.top());
someGL2.glVertex3i(-15, 6, -12);
someGL2.glTexCoord2f(coords.right(), coords.top());
someGL2.glVertex3i(15, 6, -12);
someGL2.glTexCoord2f(coords.right(), coords.bottom());
someGL2.glVertex3i(15, -6, -12);
someGL2.glEnd();
texBackground.disable();
Texture texEarth = TextureIO.newTexture(this._earthTextureData);
someGL2.glPushMatrix();
someGL2.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
someGL2.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
GLUquadric earth = someGLU.gluNewQuadric();
texEarth.enable();
texEarth.bind();
someGLU.gluQuadricTexture(earth, true);
someGLU.gluQuadricDrawStyle(earth, GLU.GLU_FILL);
someGLU.gluQuadricNormals(earth, GLU.GLU_SMOOTH);
someGLU.gluQuadricOrientation(earth, GLU.GLU_OUTSIDE);
someGLU.gluSphere(earth, 1.0, 100, 360);
someGLU.gluDeleteQuadric(earth);
texEarth.disable();
someGL2.glPopMatrix();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
@Override
public void dispose(GLAutoDrawable arg0) {
// TODO Auto-generated method stub
}
@Override
public void init(GLAutoDrawable drawable)
{
try
{
GL2 someGL2 = drawable.getGL().getGL2();
GLU someGLU = GLU.createGLU(someGL2);
InputStream stream = this.getClass().getResourceAsStream("earth.bmp");
this._earthTextureData = TextureIO.newTextureData(stream, false, "bmp");
stream = this.getClass().getResourceAsStream("stars.bmp");
this._backgroundTextureData = TextureIO.newTextureData(stream, false, "bmp");
someGL2.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
someGL2.glLoadIdentity();
someGL2.glClearColor(
0.0F,
0.0F,
0.0F,
1.0F);
double aspect =
((Component) drawable).getWidth() /
((Component) drawable).getHeight();
someGLU.gluPerspective(60.0, aspect, 2.0, 40.0);
someGL2.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
someGL2.glLoadIdentity();
someGLU.gluLookAt(
0.0, 0.0, 10.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
float[] position = {-5.0F, 0.0F, 5.0F, 1.0F};
float[] diffuse = { 0.5F, 0.5F, 0.5F, 1.0F};
float[] ambient = { 0.001F, 0.001F, 0.001F, 1.0F};
someGL2.glEnable(GLLightingFunc.GL_LIGHTING);
someGL2.glEnable(GLLightingFunc.GL_LIGHT0);
someGL2.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, position, 0);
someGL2.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, diffuse, 0);
someGL2.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_AMBIENT, ambient, 0);
someGL2.glEnable(GL2.GL_DEPTH_TEST);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
int arg4) {
// TODO Auto-generated method stub
}
}
Verwendet wird JOGL Version 2.0 und Java 6 Update 21. Als IDE kommt Eclipse 3.5.1. zum Einsatz.
Wenn ich folgende Zeile:
Java:
someGLU.gluQuadricOrientation(earth, GLU.GLU_OUTSIDE);
wie folgt abändere
Java:
someGLU.gluQuadricOrientation(earth, GLU.GLU_INSIDE);
wird die Textur richtig dargestellt, allerdings muss die Erde dann um 270 Grad gedreht werden, da sie sonst auf dem Kopf stünde. Ich nehme aber mal an, dass dies nur eine "Quick and dirty"-Lösung darstellen kann, die Richtung der Normalen der Quadric nach innen zeigen zu lassen. Zumal in allen Code-Beispielen in der Literatur stehts der Parameter GLU_OUTSIDE verwendet wird.
Muss man hierfür eine Änderung an der Texturmatrix vornehmen? (nach Umschalten auf glMatrixMode(GL.GL_TEXTURE); )
Vielen Dank bereits im Voraus!