Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] adding Texture in jogl 2 troubles  (Read 2558 times)
0 Members and 1 Guest are viewing this topic.
Offline dim_9999

Senior Newbie





« Posted 2011-01-29 23: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 Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2011-01-31 00:01:02 »

Hi!

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

Offline dim_9999

Senior Newbie





« Reply #2 - Posted 2011-01-31 00: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mickelukas

JGO Ninja


Medals: 39
Projects: 2


Java guru wanabee


« Reply #3 - Posted 2011-01-31 00:45:43 »

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

Mike

Offline dim_9999

Senior Newbie





« Reply #4 - Posted 2011-01-31 00: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


Medals: 39
Projects: 2


Java guru wanabee


« Reply #5 - Posted 2011-01-31 01: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

Senior Newbie





« Reply #6 - Posted 2011-01-31 01: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


Medals: 39
Projects: 2


Java guru wanabee


« Reply #7 - Posted 2011-01-31 01: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

Senior Newbie





« Reply #8 - Posted 2011-01-31 01: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 Ninja


Medals: 33
Projects: 1


TUER


« Reply #9 - Posted 2011-01-31 10:32:33 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dim_9999

Senior Newbie





« Reply #10 - Posted 2011-01-31 23: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 Ninja


Medals: 33
Projects: 1


TUER


« Reply #11 - Posted 2011-02-01 00: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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (79 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.517 seconds with 21 queries.