|
楼主 |
发表于 2004-12-7 11:56:00
|
显示全部楼层
Re:【for Beginners】怎样开始学习OpenGL
for JAVA HOWTO:
如果你是JAVA程序员,我向你推荐JOGL,JOGL项目是目前流行的OpenGL的JAVA绑定,它的官方主页是https://jogl.dev.java.net
当前的JOGL支持OpenGL 1.5,和绝大多数的扩展,当然如果你是OpenGL高手,你会知道,只要本地环境支持,我们一样可以调用JOGL没有提供的OpenGL扩展函数。(详细请看JGOL source code和JNI)
好吧,假定你有一个JAVA的编译环境,你的JAVA SDK版本在1.42以上,(你可以下载到netbeans,Eclipse,它们都是free的IDE)
安装步骤:
1。在https://jogl.dev.java.net的Precompiled binaries and documentation的Release Builds 2004的1.1b07 - November 19目录
下载jogl.jar和jogl-natives-win32.jar(不是windows用户的话,下载jogl-natives-myos.jar)
2。将jogl.jar安装到CLASSPATH
3。运行下面程序,得到java.library.path
public class try {
public static void main(String[] args)
{
System.out.println(System.getProperty("java.library.path"));
}
}
4。
在WINDOWS上,解压缩jogl-natives-win32.jar,将jogl.dll和joglcg.dll放到任意的java.library.path目录中
在linux上,是两个。SO文件,将其放到任意的java.library.path目录中,有可能你需要ROOT权限,这取决于你的JRE是不是在你的目录下,或许你也可以在自己的根目录中部署JRE,再部署这两个。SO文件,DIY yourself !
5。运行看下面的程序,它能跑就说明安装好了
public class zaishishi {
public static void main(String[] args)
{
System.loadLibrary("jogl" );
}
}
6。运行我们的例子hello.java
import net.java.games.jogl.*;
import java.awt.*;
import java.awt.event.*;
public class hello
{
public static void main( String[] args )
{
try
{
Frame Frame = new Frame("hello"); /*Open window with "hello"in its title bar.*/
Frame.setSize(250,250); /*Declare initial window size.*/
GLCapabilities glCaps = new GLCapabilities();
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( glCaps );
canvas.addGLEventListener(new Renderer());
Frame.add( canvas );
final Animator animator = new Animator( canvas);
Frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
System.exit(0);
}
});
Frame.show();
animator.start();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
class Renderer implements GLEventListener
{
private GL gl;
private GLDrawable glDrawable;
public void init(GLDrawable drawable)
{
this.gl = drawable.getGL();
this.glDrawable = drawable;
drawable.setGL( new DebugGL(drawable.getGL() ));
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);/* select clearing color */
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/* initialize viewing values */
}
public void display(GLDrawable drawable)
{
gl.glClear(GL.GL_COLOR_BUFFER_BIT);/* clear all pixels */
gl.glLoadIdentity();
gl.glColor3f(1.0f, 1.0f, 1.0f );
gl.glBegin( GL.GL_POLYGON); /* draw white polygon with corners at(0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)*/
gl.glVertex3f (0.25f, 0.25f, 0.0f);
gl.glVertex3f (0.75f, 0.25f, 0.0f);
gl.glVertex3f (0.75f, 0.75f, 0.0f);
gl.glVertex3f (0.25f, 0.75f, 0.0f);
gl.glEnd();
gl.glFlush();/* start processing buffered OpenGL routines */
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
}
public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
{
}
}
|
|