Переписываю проект потихоньку рантайм ошибки не пойму Cars.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cars;
/**
*
* @author Евгений
*/
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.DisplayMode;
import java.io.IOException;
/*
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
*/
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.*;
import javax.swing.JFrame;
import com.jogamp.opengl.util.FPSAnimator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Cars implements GLEventListener {
public static DisplayMode dm, dm_old;
private GLU glu = new GLU();
private float xrot,yrot,zrot;
private int texture;
static Scene1 scene;
static Vector<String> drum;
@Override
public void display(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); // Reset The View
gl.glTranslatef(0f, 0f, -5.0f);
scene.ShowDrum(5, 6, drum, gl);
gl.glFlush();
}
@Override
public void dispose(GLAutoDrawable drawable) {
// method body
}
@Override
public void init(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearColor(0f, 0f, 0f, 0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2.GL_LEQUAL);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
gl.glEnable(GL2.GL_TEXTURE_2D);
try {
scene.LoadDrum(gl);
} catch (IOException ex) {
Logger.getLogger(Cars.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
// TODO Auto-generated method stub
final GL2 gl = drawable.getGL().getGL2();
if(height <= 0)
height = 1;
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
public static void main(String[] args) {
scene = new Scene1();
scene.Scene();
drum = new Vector<String>();
for(int i=0;i<30;i++)
drum.add("auto1");
// TODO Auto-generated method stub
final GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);
// The canvas
final GLCanvas glcanvas = new GLCanvas(capabilities);
Cars r = new Cars();
glcanvas.addGLEventListener(r);
glcanvas.setSize(400, 400);
final JFrame frame = new JFrame (" Textured Cube");
frame.getContentPane().add(glcanvas);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
glcanvas.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
System.out.println(e.getX() + " " + e.getY());
}
});
final FPSAnimator animator = new FPSAnimator(glcanvas, 300, true);
animator.start();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cars;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
/**
*
* @author Евгений
*/
public class Scene1 {
class Image
{
int IndexTexture;
String Name;
int number;
}
static final int CountDrum = 5;
static final int CountTextureOnDrum = 6;
static final int CountTexture = 1;
public Vector<String> vectordrum;
int CountIndexTexture;
Image[] image;
File im;
Texture t;
float xl, xr, yd, yu;
int Scene()
{
image = new Image[CountTexture];
CountIndexTexture = 0;
vectordrum = new Vector<String>();
return 0;
}
int LoadDrum(final GL2 gl) throws IOException
{
//if (iter == 0)
{
vectordrum.add("auto1");//1
CountIndexTexture++;
im = new File("content\\drum\\auto1.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "auto1";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
/*
//if (iter == 1)
{
vectordrum.add("auto2");//2
im = new File("content\\drum\\auto2.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "auto2";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
//if (iter == 2)
{
vectordrum.add("auto3");//3
im = new File("content\\drum\\auto3.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "auto3";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
//if (iter == 3)
{
vectordrum.add("auto4");//4
im = new File("content\\drum\\auto4.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "auto4";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
//if (iter == 4)
{
vectordrum.add("auto5");//5
im = new File("content\\drum\\auto5.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "auto5";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
//if (iter == 15)
{
vectordrum.add("bonus");//16
im = new File("content\\drum\\bonus.png");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "bonus";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
//if (iter == 16)
{
vectordrum.add("wild");//17
im = new File("content\\drum\\wild.jpg");
t = TextureIO.newTexture(im, true);
image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
image[CountIndexTexture - 1].Name = "wild";
image[CountIndexTexture - 1].number = CountIndexTexture - 1;
}
*/
//if (iter > 15)
return 0;
//else
// return 1;
}
int FindTexture(String name)
{
int result = -1;
for (int i = 0; i<CountTexture; i++)
{
if (image[i].Name.equals(name))
{
result = image[i].number;
break;
}
}
return result;
}
void ShowDrum(int countdrums, int counttextureondrums,Vector<String> drum,final GL2 gl)
{
int k = -1;
for (int i = 0; i<countdrums; i++)
{
gl.glPushMatrix();
//glRotatef(rotate[i], 1, 0, 0);
for (int j = 0; j < counttextureondrums; j++)
{
gl.glBindTexture(GL2.GL_TEXTURE_2D, image[FindTexture(drum.get(++k))].IndexTexture);
EnableTexture(i, j,gl);
}
gl.glPopMatrix();
}
}
void EnableTexture(int n, int m,final GL2 gl)
{
if(n == 0)
{
if(m == 0){
xl = -0.78f;//08
xr = -0.48f;
yd = 0.3f;
yu = 0.68f;//09
EnablePolygonFrontUp(xl, xr, yd, yu,gl);
}
if (m == 1) {
xl = -0.78f;
xr = -0.48f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonFrontMiddle(xl, xr, yd, yu,gl);
}
if (m == 2) {
xl = -0.78f;
xr = -0.48f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonFrontDown(xl, xr, yd, yu,gl);
}
if (m == 3) {
xl = -0.78f;
xr = -0.48f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonBackUp(xl, xr, yd, yu,gl);
}
if (m == 4) {
xl = -0.78f;
xr = -0.48f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonBackMiddle(xl, xr, yd, yu,gl);
}
if (m == 5) {
xl = -0.78f;
xr = -0.48f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonBackDown(xl, xr, yd, yu,gl);
}
}
//front up
//front middle
if(n == 1)
{
if (m == 0) {
xl = -0.48f;
xr = -0.16f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonFrontUp(xl, xr, yd, yu,gl);
}
if(m == 1){
xl = -0.48f;
xr = -0.16f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonFrontMiddle(xl, xr, yd, yu,gl);
}
if (m == 2) {
xl = -0.48f;
xr = -0.16f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonFrontDown(xl, xr, yd, yu,gl);
}
if (m == 3) {
xl = -0.48f;
xr = -0.16f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonBackUp(xl, xr, yd, yu,gl);
}
if (m == 4) {
xl = -0.48f;
xr = -0.16f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonBackMiddle(xl, xr, yd, yu,gl);
}
if (m == 5) {
xl = -0.48f;
xr = -0.16f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonBackDown(xl, xr, yd, yu,gl);
}
}
//front middle
//front down
if(n == 2)
{
if (m == 0) {
xl = -0.16f;
xr = 0.16f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonFrontUp(xl, xr, yd, yu,gl);
}
if (m == 1) {
xl = -0.16f;
xr = 0.16f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonFrontMiddle(xl, xr, yd, yu,gl);
}
if(m == 2){
xl = -0.16f;
xr = 0.16f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonFrontDown(xl, xr, yd, yu,gl);
}
if (m == 3) {
xl = -0.16f;
xr = 0.16f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonBackUp(xl, xr, yd, yu,gl);
}
if (m == 4) {
xl = -0.16f;
xr = 0.16f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonBackMiddle(xl, xr, yd, yu,gl);
}
if (m == 5) {
xl = -0.16f;
xr = 0.16f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonBackDown(xl, xr, yd, yu,gl);
}
}
//front down
//back up
if(n == 3)
{
if (m == 0) {
xl = 0.16f;
xr = 0.48f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonFrontUp(xl, xr, yd, yu,gl);
}
if (m == 1) {
xl = 0.16f;
xr = 0.48f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonFrontMiddle(xl, xr, yd, yu,gl);
}
if (m == 2) {
xl = 0.16f;
xr = 0.48f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonFrontDown(xl, xr, yd, yu,gl);
}
if(m == 3){
xl = 0.16f;
xr = 0.48f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonBackUp(xl, xr, yd, yu,gl);
}
if (m == 4) {
xl = 0.16f;
xr = 0.48f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonBackMiddle(xl, xr, yd, yu,gl);
}
if (m == 5) {
xl = 0.16f;
xr = 0.48f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonBackDown(xl, xr, yd, yu,gl);
}
}
//back up
//back middle
if(n == 4)
{
if (m == 0) {
xl = 0.48f;
xr = 0.78f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonFrontUp(xl, xr, yd, yu,gl);
}
if (m == 1) {
xl = 0.48f;
xr = 0.78f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonFrontMiddle(xl, xr, yd, yu,gl);
}
if (m == 2) {
xl = 0.48f;
xr = 0.78f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonFrontDown(xl, xr, yd, yu,gl);
}
if (m == 3) {
xl = 0.48f;
xr = 0.78f;
yd = 0.3f;
yu = 0.68f;
EnablePolygonBackUp(xl, xr, yd, yu,gl);
}
if(m == 4){
xl = 0.48f;
xr = 0.78f;
yd = -0.3f;
yu = 0.3f;
EnablePolygonBackMiddle(xl, xr, yd, yu,gl);
}
if (m == 5) {
xl = 0.48f;
xr = 0.78f;
yd = -0.68f;
yu = -0.3f;
EnablePolygonBackDown(xl, xr, yd, yu,gl);
}
}
//back middle
}
void EnablePolygonFrontUp(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, yup, 0.0f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, ydown, .6f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, ydown, .6f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, yup, 0.0f);
gl.glEnd();
}
void EnablePolygonFrontMiddle(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, yup, .6f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, ydown, .6f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, ydown, .6f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, yup, .6f);
gl.glEnd();
}
void EnablePolygonFrontDown(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, yup, .6f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, ydown, 0.0f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, ydown, 0.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, yup, .6f);
gl.glEnd();
}
void EnablePolygonBackUp(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, ydown, -.6f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, yup, 0.0f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, yup, 0.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, ydown, -.6f);
gl.glEnd();
}
void EnablePolygonBackMiddle(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, ydown, -.6f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, yup, -.6f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, yup, -.6f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, ydown, -.6f);
gl.glEnd();
}
void EnablePolygonBackDown(float xleft, float xright, float ydown, float yup,final GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(xleft, ydown, 0.0f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(xleft, yup, -.6f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(xright, yup, -.6f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(xright, ydown, 0.0f);
gl.glEnd();
}
}