Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 3406 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

« In padded room »



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 Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


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

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
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 Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


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

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
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 Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


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?

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
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

« In padded room »



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

« In padded room »



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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (48 views)
2014-04-15 18:08:23

BurntPizza (44 views)
2014-04-15 03:46:01

UprightPath (60 views)
2014-04-14 17:39:50

UprightPath (42 views)
2014-04-14 17:35:47

Porlus (58 views)
2014-04-14 15:48:38

tom_mai78101 (82 views)
2014-04-10 04:04:31

BurntPizza (140 views)
2014-04-08 23:06:04

tom_mai78101 (240 views)
2014-04-05 13:34:39

trollwarrior1 (200 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!