Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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  
  mixing java2d and jogl2 troubles  (Read 1112 times)
0 Members and 1 Guest are viewing this topic.
Offline dim_9999

Senior Newbie





« Posted 2011-02-01 03:52:18 »

Hello everybody!

I try to explain my problem...
I am trying to use GLJpanel as canvas instead GLCanvas. So, on my top frame, i put my JPanel and enclosing canvas; JPanel contains some gradient as background and a text at front. So, if i want to see my  JPanel, i need to set up canvas.setOpaque(false) for transparent view, and in init() metod set gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f), i guess... well, at finally i got an exception...

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  
package book;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.media.opengl.GL;
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.GLJPanel;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jogamp.opengl.util.FPSAnimator;

public class Simple2DText extends JFrame implements GLEventListener {
private GLU glu;
private static final double Z_DIST = 7.0;    // for camera position
private static Font font;
   /**
    * @param args
    */

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

      EventQueue.invokeLater(new Runnable() {
         public void run() {
            Simple2DText frame = new Simple2DText();
            frame.add(makeRenderPanel());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
         }
      });
   }

   
   public void display(GLAutoDrawable drawable) {
      GL2 gl = drawable.getGL().getGL2();
      // clear color and depth buffers
     gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      gl.glLoadIdentity();
      glu.gluLookAt(0,0,Z_DIST, 0,0,0, 0,1,0);   // position camera
     
   }

   @Override
   public void dispose(GLAutoDrawable arg0) {
      // TODO Auto-generated method stub
     
   }

   
   public void init(GLAutoDrawable drawable) {
     
      GL2 gl = drawable.getGL().getGL2();    // don't make this gl a global!
     glu = new GLU();
     
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      gl.glEnable(GL.GL_DEPTH_TEST);
      drawable.addGLEventListener(this);
     
      FPSAnimator animator = new FPSAnimator(60, true);
      animator.start();
   }

   
   public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
      GL2 gl = drawable.getGL().getGL2();
      if (height == 0)height = 1;    // to avoid division by 0 in aspect ratio below
     gl.glViewport(x, y, width, height);  // size of drawing area
     gl.glMatrixMode(GL2.GL_PROJECTION);
      gl.glLoadIdentity();
      glu.gluPerspective(45.0, (float)width/(float)height, 1, 100);
               // FOV, aspect ratio, near & far clipping planes
     gl.glMatrixMode(GL2.GL_MODELVIEW);
      gl.glLoadIdentity();
     
   }
   private static JPanel makeRenderPanel() {
//      JPanel renderPane = new JPanel();
     font = new Font("SansSerif", Font.BOLD, 48);
      JPanel renderPane = new JPanel() {
         public void paintComponent(Graphics g){
            Graphics2D g2d = (Graphics2D) g;
            int width = getWidth();
            int height = getHeight();
            g2d.setPaint( new GradientPaint(0, 0, Color.YELLOW,   width, height, Color.BLUE));
            g2d.fillRect(0, 0, width, height);
            g2d.setPaint(Color.BLACK);
            g2d.setFont(font);
            g2d.drawString("Hello World", width/4, height/4);
         }
      };
      renderPane.setLayout(new BorderLayout());
      renderPane.setOpaque(false);
      renderPane.setPreferredSize(new Dimension(400, 300));
//      GLCanvas canvas = new GLCanvas(); // the canvas
     
      // create the GLJPanel
     GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
      caps.setAlphaBits(8);
      GLJPanel canvas = new GLJPanel(caps);
      canvas.setOpaque(false);
     
      // the animator uses fixed rate scheduling
     renderPane.add(canvas, BorderLayout.CENTER);
      return renderPane;
   }
   
}


here is 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  
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  
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Unable to set pixel format 40 for device 
context 0xffffffff8f011b0c: error code 0   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfigurationGDI(WindowsWGLGraphicsConfigurationFactory.java:449)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfiguration(WindowsWGLGraphicsConfigurationFactory.java:247)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfiguration(WindowsWGLGraphicsConfigurationFactory.java:186)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfiguration.
updateGraphicsConfiguration(WindowsWGLGraphicsConfiguration.java:140)
   at com.jogamp.opengl.impl.windows.wgl.WindowsBitmapWGLDrawable.
create(WindowsBitmapWGLDrawable.java:153)
   at com.jogamp.opengl.impl.windows.wgl.WindowsBitmapWGLDrawable.
<init>(WindowsBitmapWGLDrawable.java:61)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory.
createOffscreenDrawableImpl(WindowsWGLDrawableFactory.java:368)
   at com.jogamp.opengl.impl.GLDrawableFactoryImpl.createGLDrawable(GLDrawableFactoryImpl.java:117)
   at com.jogamp.opengl.impl.GLDrawableFactoryImpl.createOffscreenDrawable(GLDrawableFactoryImpl.java:213)
   at javax.media.opengl.awt.GLJPanel$SoftwareBackend.initialize(GLJPanel.java:1018)
   at javax.media.opengl.awt.GLJPanel.createAndInitializeBackend(GLJPanel.java:618)
   at javax.media.opengl.awt.GLJPanel.access$2200(GLJPanel.java:126)
   at javax.media.opengl.awt.GLJPanel$PbufferBackend.initialize(GLJPanel.java:1121)
   at javax.media.opengl.awt.GLJPanel.createAndInitializeBackend(GLJPanel.java:618)
   at javax.media.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:368)
   at javax.swing.JComponent.paint(JComponent.java:1029)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
   at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
   at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
   at javax.swing.JComponent.paint(JComponent.java:1015)
   at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
   at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
   at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
   at java.awt.Container.paint(Container.java:1780)
   at java.awt.Window.paint(Window.java:3375)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
   at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
   at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   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)
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException:
Unable to set pixel format 40 for device context 0xffffffffa7010104: error code 1
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfigurationGDI(WindowsWGLGraphicsConfigurationFactory.java:449)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfiguration(WindowsWGLGraphicsConfigurationFactory.java:247)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.
updateGraphicsConfiguration(WindowsWGLGraphicsConfigurationFactory.java:186)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfiguration.
updateGraphicsConfiguration(WindowsWGLGraphicsConfiguration.java:140)
   at com.jogamp.opengl.impl.windows.wgl.WindowsBitmapWGLDrawable.create(WindowsBitmapWGLDrawable.java:153)
   at com.jogamp.opengl.impl.windows.wgl.WindowsBitmapWGLDrawable.<init>(WindowsBitmapWGLDrawable.java:61)
   at com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory.
createOffscreenDrawableImpl(WindowsWGLDrawableFactory.java:368)
   at com.jogamp.opengl.impl.GLDrawableFactoryImpl.createGLDrawable(GLDrawableFactoryImpl.java:117)
   at com.jogamp.opengl.impl.GLDrawableFactoryImpl.createOffscreenDrawable(GLDrawableFactoryImpl.java:213)
   at javax.media.opengl.awt.GLJPanel$SoftwareBackend.initialize(GLJPanel.java:1018)
   at javax.media.opengl.awt.GLJPanel.createAndInitializeBackend(GLJPanel.java:618)
   at javax.media.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:368)
   at javax.swing.JComponent.paint(JComponent.java:1029)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paint(JComponent.java:1038)
   at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
   at javax.swing.JComponent.paintChildren(JComponent.java:862)
   at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
   at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
   at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
   at javax.swing.JComponent.paint(JComponent.java:1015)
   at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
   at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
   at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
   at java.awt.Container.paint(Container.java:1780)
   at java.awt.Window.paint(Window.java:3375)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
   at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
   at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   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)


any ideas where i was wrong? thanks.

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline gouessej
« Reply #1 - Posted 2011-02-01 09:19:38 »

Hi!

I'm not sure, I think it is a known bug of JOGL. GLJPanel is a bit broken, avoid using it if possible. I have no access to Microsoft Windows and your bug is specific to this platform. Please ask some help here: http://jogamp.762907.n3.nabble.com/jogl-f782158.html

Offline dim_9999

Senior Newbie





« Reply #2 - Posted 2011-02-01 22:26:19 »

Hi!

I'm not sure, I think it is a known bug of JOGL. GLJPanel is a bit broken, avoid using it if possible. I have no access to Microsoft Windows and your bug is specific to this platform. Please ask some help here: http://jogamp.762907.n3.nabble.com/jogl-f782158.html

Hi! Ok, thanks. I will try...

Love is a lonely laughter resonant in the middle of endless moaning of hell
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.

radar3301 (11 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (47 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!