Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  [solved] adding Texture in jogl 2 troubles  (Read 1452 times)
0 Members and 2 Guests are viewing this topic.
Offline dim_9999

JGO n00b
*

Posts: 15



« on: 2011-01-29 17:28:09 »

Hello world!
I am trying to add texture to the sphere, but i got an exception: Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glTexParameteri(<int> 0xDE1, <int> 0x8191, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
...

Here is the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
import java.awt.EventQueue;

import javax.media.opengl.DebugGL;
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.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.swing.JFrame;

import com.sun.opengl.util.FPSAnimator;
import com.sun.opengl.util.texture.Texture;

@SuppressWarnings("serial")
public class MyGLCanvas extends GLCanvas implements GLEventListener {

   private static MyGLCanvas canvas = new MyGLCanvas(300, 300, new GLCapabilities());
   private static FPSAnimator animator;
   private GLU glu;
   private Texture earthTexture;

   public MyGLCanvas(int width, int height, GLCapabilities cap) {
      super(cap);
      setSize(width, height);

      cap.setRedBits(8);
      cap.setBlueBits(8);
      cap.setGreenBits(8);
      cap.setAlphaBits(8);
      addGLEventListener(this);
   }

   @Override
   public void display(GLAutoDrawable drawable) {
      // TODO Auto-generated method stub
     GL gl = drawable.getGL();
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      setCamera(gl, glu, 30);

     
      // Prepare light parameters.
     float SHINE_ALL_DIRECTIONS = 1;
      float[] lightPos = { -30, 0, 0, SHINE_ALL_DIRECTIONS };
      float[] lightColorAmbient = { 0.2f, 0.2f, 0.2f, 1f };
      float[] lightColorSpecular = { 0.8f, 0.8f, 0.8f, 1f };
      // Set light parameters.
     gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPos, 0);
      gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightColorAmbient, 0);
      gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, lightColorSpecular, 0);
      // Enable lighting in GL.
     gl.glEnable(GL.GL_LIGHT1);
      gl.glEnable(GL.GL_LIGHTING);
      // Set material properties.
     float[] rgba = { 1f, 1f, 1f };
      gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, rgba, 0);
      gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, rgba, 0);
      gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 0.5f);

      earthTexture.enable();
      earthTexture.bind();
//      gl.glBegin(GL.GL_QUADS);
     GLUquadric earth = glu.gluNewQuadric();

      glu.gluQuadricTexture(earth, true);
      glu.gluQuadricDrawStyle(earth, GLU.GLU_FILL);
      glu.gluQuadricNormals(earth, GLU.GLU_FLAT);
      glu.gluQuadricOrientation(earth, GLU.GLU_OUTSIDE);
      final float radius = 6.378f;
      final int slices = 16;
      final int stacks = 16;
      glu.gluSphere(earth, radius, slices, stacks);
      glu.gluDeleteQuadric(earth);
     
//      gl.glEnd();
     
   }

   private void setCamera(GL gl, GLU glu2, int distance) {
      // TODO Auto-generated method stub
     // Change to projection matrix.
     gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      // Perspective.
     float widthHeightRatio = (float) getWidth() / (float) getHeight();
      glu.gluPerspective(45, widthHeightRatio, 1, 1000);
     
      glu.gluLookAt(0, 0, distance, 0, 0, 0, 0, 1, 0);
      // Change back to model view matrix.
     gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
   }

   

   @Override
   public void init(GLAutoDrawable drawable) {
      // TODO Auto-generated method stub
     GL gl = drawable.getGL();
     
      drawable.setGL(new DebugGL(gl));
      // Global settings.
     // Enable z- (depth) buffer for hidden surface removal.
     gl.glEnable(GL.GL_DEPTH_TEST);
      gl.glDepthFunc(GL.GL_LEQUAL);
      // Enable smooth shading.
     gl.glShadeModel(GL.GL_SMOOTH);
      // We want a nice perspective.
     gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
      // Define "clear" color.
     gl.glClearColor(0f, 0f, 0f, 1f);
      glu = new GLU();
      // add Texture

      earthTexture = LoadTexture.loadTexture("earthmap1k.jpg");
     
      // Start animator (which should be a field).
     animator = new FPSAnimator(this, 60);
      animator.start();
   }

   @Override
   public void reshape(GLAutoDrawable drawable, int x, int y, int width,
         int height) {
      // TODO Auto-generated method stub
     GL gl = drawable.getGL();
      gl.glViewport(0, 0, width, height);
   }

   /**
    * @param args
    */

   public static void main(String[] args) {
      // TODO Auto-generated method stub

      EventQueue.invokeLater(new Runnable() {
         public void run() {
            JFrame frame = new JFrame("Universe");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(canvas.getPreferredSize());
            frame.getContentPane().add(canvas);
            frame.setVisible(true);

         }
      });

      canvas.requestFocus();
   }

   @Override
   public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
      // TODO Auto-generated method stub
     
   }

}


Here is LoadTexture:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
import java.io.File;
import java.io.IOException;

import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;

public class LoadTexture {
    public static Texture loadTexture (String name){
        Texture texture = null;
            try {
               texture = TextureIO.newTexture(new File(name), true);// bool - mipmap.
             
               
            } catch (IOException e) {
                System.out.println("fail openning file... " + name);
                System.out.println(e);
            }
            return texture;
    }
}

Any ideas how to fix that? Thanks.

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #1 on: 2011-01-30 18:01:02 »

Hi!

If you want some help, please post the full stack trace and tell us more about your image.

Julien Gouesse
Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #2 on: 2011-01-30 18:26:23 »

Hi!

If you want some help, please post the full stack trace and tell us more about your image.

Hi! Ok.
 
Here is the stack trace:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the 
following error codes after a call to glTexParameteri(<int> 0xDE1, <int> 0x8191, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
   at javax.media.opengl.DebugGL2.checkGLGetError(DebugGL2.java:32455)
   at javax.media.opengl.DebugGL2.glTexParameteri(DebugGL2.java:9843)
   at com.jogamp.opengl.util.texture.Texture.updateImage(Texture.java:642)
   at com.jogamp.opengl.util.texture.Texture.updateImage(Texture.java:421)
   at com.jogamp.opengl.util.texture.Texture.<init>(Texture.java:183)
   at com.jogamp.opengl.util.texture.TextureIO.newTexture(TextureIO.java:406)
   at com.jogamp.opengl.util.texture.TextureIO.newTexture(TextureIO.java:427)
   at LoadTexture.loadTexture(LoadTexture.java:14)
   at MyGLCanvas.init(MyGLCanvas.java:167)
   at com.jogamp.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:153)
   at com.jogamp.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:167)
   at javax.media.opengl.awt.GLCanvas$InitAction.run(GLCanvas.java:776)
   at com.jogamp.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:348)
   at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:711)
   at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:361)
   at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:464)
   at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
   at sun.awt.RepaintArea.paint(RepaintArea.java:224)
   at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:310)
   at java.awt.Component.dispatchEventImpl(Component.java:4706)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


The image is a *.jpg with dimensions 1000*500... [You can see her at http://planetpixelemporium.com/images/mappreviews/earthmapthumb.jpg]

Love is a lonely laughter resonant in the middle of endless moaning of hell
Games published by our own members! Go get 'em!
Offline Mickelukas

JGO Ninja
***

Posts: 731
Medals: 25


Java guru wanabee


« Reply #3 on: 2011-01-30 18:45:43 »

First of all make sure you use a power of 2 texture size (for example 1024*512) Smiley

Mike

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #4 on: 2011-01-30 18:54:37 »

First of all make sure you use a power of 2 texture size (for example 1024*512) Smiley

Mike

Hi Mike! Thanks for answer. I set size of my picture to 1024x512, but exception is the same...

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline Mickelukas

JGO Ninja
***

Posts: 731
Medals: 25


Java guru wanabee


« Reply #5 on: 2011-01-30 19:05:45 »

Humm... I can't get to the jpg, I get an "Forbidden You don't have permission to access /images/mappreviews/earthmapthumb.jpg on this server."

Maybe upload it somewhere else?

Also, did you test the function with something else than a jpg (like a png or bmp) to see if it is only the picture?

Mike

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #6 on: 2011-01-30 19:11:57 »

Humm... I can't get to the jpg, I get an "Forbidden You don't have permission to access /images/mappreviews/earthmapthumb.jpg on this server."

Maybe upload it somewhere else?

Mike

Sure! Try this earthmap1k_1024x512.jpg
from rapidshare: earthmap1k_1024x512.jpg
Yes, i did. i try to use *.png, *.bmp but the result is the same...

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline Mickelukas

JGO Ninja
***

Posts: 731
Medals: 25


Java guru wanabee


« Reply #7 on: 2011-01-30 19:14:21 »

That link wants to install software on my computer from some russian site Tongue

Tried it with a png or bmp?

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #8 on: 2011-01-30 19:34:22 »

That link wants to install software on my computer from some russian site Tongue

Tried it with a png or bmp?

i try to use *.png, *.bmp but the result is the same...

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #9 on: 2011-01-31 04:32:33 »

Please rather use a recent build of JOGL 2.0 to reproduce this bug, your version seems quite old.

Julien Gouesse
Games published by our own members! Go get 'em!
Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #10 on: 2011-01-31 17:51:07 »

Please rather use a recent build of JOGL 2.0 to reproduce this bug, your version seems quite old.

I download latest autobild from master folder... and all works fine!:)

Thanks man!))



Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #11 on: 2011-01-31 18:40:36 »

I download latest autobild from master folder... and all works fine!:)

Thanks man!))



You're welcome  Grin JOGL is alive and we do our best to help developers to use it.

Julien Gouesse
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.09 seconds with 20 queries.