gpt4 book ai didi

java - JOGL 2.0 不支持 GLCanvas ,Texture ,Animator ,但是 jogl 1.0 呢?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:49:18 27 4
gpt4 key购买 nike

我从 here 下载了 jogl 2.0 ,文件 jogl-all.jar ,并运行了一个取自 here 的简单代码示例:

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;

import com.sun.opengl.util.Animator;

/**
* This is a simple example for the method
*
* glNormal();
*
*
* Keyboard commands:
*
* Key A) Increase the deltaZ value
*
* Key B) Decrease the deltaZ value
*
* Key C) Increase the deltaX value
*
* Key D) Decrease the deltaX value
*
* Key E) Increase the deltaY value
*
* Key F) Decrease the deltaY value
*
* @author Alessandro Martinelli
*/
public class Practice11IlluminateGeometry extends JFrame implements KeyListener{

private static float deltaZ=0;
private static float deltaX=0;
private static float deltaY=0;


public static void main(String[] args) {
Practice11IlluminateGeometry frame=new Practice11IlluminateGeometry();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}

public Practice11IlluminateGeometry(){
setSize(600,600);
setTitle("Hello Universe");

GraphicListener listener=new GraphicListener();
GLCanvas canvas = new GLCanvas(new GLCapabilities());
canvas.addGLEventListener(listener);
getContentPane().add(canvas);

Animator animator = new Animator(canvas);
animator.start();

addKeyListener(this);
}

public class GraphicListener implements GLEventListener{


public void display(GLAutoDrawable arg0) {

GL gl=arg0.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glEnable(GL.GL_DEPTH_TEST);
gl.glCullFace(GL.GL_FRONT);
gl.glEnable(GL.GL_CULL_FACE);
gl.glFrontFace(GL.GL_CW);


gl.glLoadIdentity();
gl.glTranslatef(deltaX, deltaY, deltaZ);

gl.glColor3f(1,1,1);
gl.glBegin(GL.GL_TRIANGLE_STRIP);

gl.glNormal3f(0, 0, 1);
gl.glVertex3f(0,0,0);
gl.glVertex3f(0.3f,0,-0.4f);
gl.glVertex3f(0,0.3f,0);
gl.glVertex3f(0.3f,0.3f,0.4f);
gl.glVertex3f(0.3f,0.6f,0);

gl.glEnd();

}

public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {

}

public void init(GLAutoDrawable arg0) {

GL gl=arg0.getGL();
gl.glEnable(GL.GL_LIGHTING);

float ambient[]= {0.2f,0.2f,0.2f,1};
gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT , ambient,0);

gl.glEnable(GL.GL_LIGHT0);
float position[]= {-0.4f,0.5f,0.7f,1};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, position, 0);
float intensity[]= {1,1,1,1};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, intensity, 0);

gl.glEnable(GL.GL_LIGHT1);
float position2[]= {0,-0.8f,0.3f,1};
gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, position2, 0);
float intensity2[]= {1,0,0,0};
gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, intensity2, 0);
float specIntensity2[]= {1,1,1,1};
gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, specIntensity2, 0);


gl.glEnable(GL.GL_COLOR_MATERIAL);
gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
float specColor[]= {1,1,1,1};
gl.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR, specColor,0);
gl.glMaterialf(GL.GL_FRONT_AND_BACK,GL.GL_SHININESS, 80);
}

public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {

}
}

public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode()==KeyEvent.VK_A){
deltaZ+=0.05;
}
if(arg0.getKeyCode()==KeyEvent.VK_B){
deltaZ-=0.05;
}
if(arg0.getKeyCode()==KeyEvent.VK_C){
deltaX+=0.05;
}
if(arg0.getKeyCode()==KeyEvent.VK_D){
deltaX-=0.05;
}
if(arg0.getKeyCode()==KeyEvent.VK_E){
deltaY+=0.05;
}
if(arg0.getKeyCode()==KeyEvent.VK_F){
deltaY-=0.05;
}
}

public void keyReleased(KeyEvent arg0) {

}

public void keyTyped(KeyEvent arg0) {

}

static final long serialVersionUID=100;
}

我得到了:

The import javax.media.opengl.GLCanvas cannot be resolved
The import com.sun.opengl cannot be resolved

还有一些(来自其他项目):

Texture cannot be resolved to a type
Animator cannot be resolved to a type

我猜 jar 不支持这些类型,这是为什么呢?有什么办法解决这个问题吗?

这很奇怪,因为 2.0 版假设支持 1.0 版支持的所有内容,或者我错了?

此外,此代码适用于 jogl 1.0,但我必须使用 2.0 版。

最佳答案

在 jogl 1.1 和 2.0 之间,jogl 项目的顶级包名称从 javax.media.opengl 更改为 com.jogamp.opengl

对于列出的两种情况,Animator 类现在可以在 com.jogamp.opengl.util.Animator 下找到,而 Texture 现在位于 com.jogamp.opengl.util 包中。纹理.纹理

jogl 的 javadoc 应该有助于找到您丢失的任何其他类。 https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/

关于java - JOGL 2.0 不支持 GLCanvas ,Texture ,Animator ,但是 jogl 1.0 呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16318817/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com