Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Pbuffers no longer working with the latest CVS  (Read 1966 times)
0 Members and 1 Guest are viewing this topic.
Offline javazoid

Junior Devvie




Where's Flender?


« Posted 2005-01-19 07:08:43 »

Looks like the Pbuffers no longer work with the latest LWJGL CVS. Can someone confirm ?

java.lang.IllegalStateException: Pbuffers are not supported
     at org.lwjgl.opengl.Pbuffer.<init>(Pbuffer.java:179)
     at PbufferTest.initialize(PbufferTest.java:124)
     at PbufferTest.execute(PbufferTest.java:109)

Offline elias

Senior Devvie





« Reply #1 - Posted 2005-01-19 09:42:21 »

Are you using the latest native lib too? Try:

http://odense.kollegienet.dk/~/naur/lwjgl_19012005.zip

- elias

Offline elias

Senior Devvie





« Reply #2 - Posted 2005-01-19 09:48:19 »

If yes, what does Pbuffer.getCapabilities() return?

- elias

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

Senior Devvie





« Reply #3 - Posted 2005-01-19 10:19:32 »

Ah, my bad. It's fixed in:

http://odense.kollegienet.dk/~naur/lwjgl_19012005-2.zip

- elias

Offline javazoid

Junior Devvie




Where's Flender?


« Reply #4 - Posted 2005-01-19 11:27:50 »

I can confirm that now it works. BRAVO!

Now I have a little problem (still in the previous version). I get:

org.lwjgl.opengl.OpenGLException: Invalid operation (1282) at org.lwjgl.opengl.Pbuffer.destroy(Pbuffer.java:240)

it happens systematically after using ogl display lists with pbuffers. No problems if I open a Display.

Offline elias

Senior Devvie





« Reply #5 - Posted 2005-01-19 11:41:35 »

I'm not sure that's our fault. Try a call to org.lwjgl.Util.checkGLError() just before the destroy(). If that is failing too, it's  probably caused by an erroneous GL call.

- elias

Offline javazoid

Junior Devvie




Where's Flender?


« Reply #6 - Posted 2005-01-19 11:50:58 »

I get no errors in the Util.checkGLError();

I also get no errors if I do not call the Destroy(), so I'm quite sure that the problem is there.

Offline elias

Senior Devvie





« Reply #7 - Posted 2005-01-19 17:26:01 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
    public void destroy() {
        try {
            makeCurrent();
            int error = GL11.glGetError();
            Display.getImplementation().destroyPbuffer(handle);
            GLContext.useContext(null);
            GLContext.unloadOpenGLLibrary();
            if (error != GL11.GL_NO_ERROR)
                throw new OpenGLException(error);
        } catch (LWJGLException e) {
            // ignore exception
        }
    }


This is the Pbuffer.destroy() code. Could you try doing a Util.checkGLError() after making sure that the pbuffer is current?

- elias

Offline javazoid

Junior Devvie




Where's Flender?


« Reply #8 - Posted 2005-01-20 07:24:21 »

Here's the test case code. It uses display lists to convert a java2d shape into a glist.

Just change the display boolean to switch from Display to PBuffer. When Display is true everything works fine. Otherwise (pbuffer mode) you'll get an exception during the cleanup.

Cheers!

Mik


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  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
/*
 * PBUFFER TEST FOR ELIAS "PBuffer Invalid operation (1282)"
 */



import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.FlatteningPathIterator;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.EXTBgra;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Pbuffer;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.opengl.glu.GLU;

public class PbufferTestElias
{
      private static Pbuffer pbuffer = null;
      private static int width = 640;
      private static int height = 400;
      private static boolean display = false;            // CHANGE THIS TO SWITCH PBUFFER/DISPLAY

      private PbufferTestElias()
      {
      }

      private static void init() throws Exception
      {            
            if (display)
            {
                  // create the display
                  DisplayMode mode = findDisplayMode(width, height, 24);
                  Display.setDisplayMode(mode);
                  // start of in windowed mode
                  Display.create();
                  Display.setVSyncEnabled(false);
                  Display.makeCurrent();
            }
            else
            {
                  // allocate the pbuffer
                  pbuffer = new Pbuffer(width, height, new PixelFormat(8, 24, 0, 0), null, null);
                  pbuffer.makeCurrent();
            }
           
            initGL(width, height);
      }

      private static void render() throws Exception
      {
            Shape shp;
           
            //Shape shp = new Ellipse2D.Float(0, 0, width, height);
           
            Font fnt = new Font("dialog",Font.BOLD,50);
            shp = fnt.createGlyphVector(new FontRenderContext(AffineTransform.getTranslateInstance(0,0),true,true),"Mik Of ClassX").getOutline();
            shp = AffineTransform.getTranslateInstance(50,150).createTransformedShape(shp);

            int list_base = GL11.glGenLists(1);
            createShape(shp, list_base);

            GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_LINE);
            GL11.glLineWidth(2f);
           
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            if (display) GL11.glColor3f(1.0f, 1.0f, 1.0f);
            else GL11.glColor3f(0.0f, 0.0f, 0.0f);
            GL11.glCallList(list_base);
            GL11.glFlush();

            GL11.glDeleteLists(list_base, 1);
           
            display(screenShot(width, height));
      }

      private static void cleanup()
      {
            try
            {
                  if (pbuffer != null)
                  {
                        pbuffer.makeCurrent();
                        pbuffer.destroy();
                  }
            }
            catch (LWJGLException e)
            {
                  e.printStackTrace();
            }

            if (Display.isCreated()) Display.destroy();
      }

      // find a nice display mode
      public static DisplayMode findDisplayMode(int width, int height, int bpp)
      {
            DisplayMode[] modes = Display.getAvailableDisplayModes();
            for (int i = 0; i < modes.length; i++)
            {
                  if (modes[i].getWidth() == width && modes[i].getHeight() == height && modes[i].getBitsPerPixel() >= bpp)
                  {
                        return modes[i];
                  }
            }
            return null;
      }
     
     
      public static void main(String[] args)
      {
            try
            {
                  init();
                  render();
            }
            catch (Exception e)
            {
                  e.printStackTrace(System.err);
                  Sys.alert("", "An error occured and the game will exit.");
            }
            finally
            {
                  cleanup();
            }
      }

      // init the geometry of the current context
      public static void initGL(int width, int height)
      {
            try
            {
                  // init geometry
                  GL11.glMatrixMode(GL11.GL_PROJECTION);
                  GL11.glLoadIdentity();
                  GLU.gluOrtho2D(0, width, 0, height);
                  GL11.glMatrixMode(GL11.GL_MODELVIEW);
                  GL11.glLoadIdentity();
                  GL11.glViewport(0, 0, width, height);

                  // init graphics blending (ALPHA COMPOSITE is SrcOver)
                  GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                  GL11.glEnable(GL11.GL_BLEND);

                  // various settings

                  //GL11.glEnable(GL11.GL_POLYGON_SMOOTH); // NO! -> TEXTURES UGLY!
                  GL11.glEnable(GL11.GL_LINE_SMOOTH);

                  GL11.glDisable(GL11.GL_DEPTH_TEST);
                  GL11.glDisable(GL11.GL_SCISSOR_TEST);
                  GL11.glDisable(GL11.GL_STENCIL_TEST);
                  GL11.glDisable(GL11.GL_ALPHA_TEST);

                  // clear background
                  GL11.glClearColor(0f, 0f, 0f, 0f);
                  GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
      }

      // create the list
      // very simple conversion method. Does not handle complex shapes or compound shapes (like glyphs).
      // also does not support open shapes (lines, arcs, etc.).
      private static void createShape(Shape shp, int list_id)
      {
            // the path iterator
            FlatteningPathIterator fpi = new FlatteningPathIterator(shp.getPathIterator(null), .01);

            // create the list
            GL11.glNewList(list_id, GL11.GL_COMPILE);

            // the generation mode
            int mode = GL11.GL_POLYGON;

            // various temp storage
            double[] c = { 0, 0, 0, 0, 0, 0 };
            boolean start = false;
            double sx = 0, sy = 0;

            while (!fpi.isDone())
            {
                  switch (fpi.currentSegment(c))
                  {
                        case FlatteningPathIterator.SEG_LINETO:
                              //System.out.println("FlatteningPathIterator.SEG_LINETO "+c[0]+" "+c[1]);
                              if (start)
                              {
                                    GL11.glVertex2f((float) c[0], (float) c[1]);
                              }
                        break;

                        case FlatteningPathIterator.SEG_MOVETO:
                              //System.out.println("FlatteningPathIterator.SEG_MOVETO "+c[0]+" "+c[1]);
                              start = true;
                              GL11.glBegin(mode);
                              GL11.glTranslatef((float) c[0], (float) c[1], 0);
                              sx = c[0];
                              sy = c[1];
                        break;

                        case FlatteningPathIterator.SEG_CLOSE:
                              // System.out.println("FlatteningPathIterator.SEG_CLOSE "+c[0]+" "+c[1]);
                              //GL11.glVertex2f((float)sx,(float)sy);
                              GL11.glEnd();
                              start = false;
                        break;
                  }
                  fpi.next();
            }

            GL11.glEndList();
            //GL11.glFlush();
      }

      // "slowly" take a screenshot of the pbuffer contents
      public static BufferedImage screenShot(int width, int height)
      {
            BufferedImage image = null;

            // allocate space for RBGA pixels
            ByteBuffer fb = BufferUtils.createByteBuffer(width * height * 4);
            int[] pixels = new int[width * height];
            int bindex;

            /*
             // grab a copy of the current frame contents as RGBA
             GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, fb);

             // convert RGBA data in ByteBuffer to integer array
             for (int i = 0; i < pixels.length; i++)
             {
             bindex = i * 4;
             int a = fb.get(bindex + 3) & 0xff;
             int r = fb.get(bindex + 0) & 0xff;
             int g = fb.get(bindex + 1) & 0xff;
             int b = fb.get(bindex + 2) & 0xff;
             pixels[i] = (a << 24) | (r << 16) | (g << 8) | (b);
             }
             */


            // we have the EXTBgra.GL_BGRA_EXT extension, so we can convert while reading!!
            GL11.glReadPixels(0, 0, width, height, EXTBgra.GL_BGRA_EXT, GL11.GL_UNSIGNED_BYTE, fb);
            fb.asIntBuffer().get(pixels);

            // Create a BufferedImage with the RGBA pixels
            try
            {
                  image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                  image.setRGB(0, 0, width, height, pixels, 0, width);
            }
            catch (Exception e)
            {
                  System.out.println("ScreenShot() exception: " + e);
            }
            return image;
      }

      private static void display(BufferedImage img)
      {
            final JFrame frame = new JFrame("PBuffer Test");
            frame.setSize(width,height);
            frame.setBackground(Color.black);
           
            // Display the pbuffer in a JScrollPane
            ImageIcon image = new ImageIcon(img);
            JLabel label = new JLabel(image);
            JScrollPane scrollPane = new JScrollPane(label);
            frame.getContentPane().add(scrollPane);

            frame.addWindowListener(new WindowAdapter()
            {
                  public void windowClosing(WindowEvent e)
                  {
                        frame.dispose();
                  }
            });
            frame.setVisible(true);
      }
}

Offline princec

« JGO Spiffy Duke »


Medals: 973
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2005-01-20 09:40:13 »

Aha, you appear to be calling glTranslatef inside a glBegin/glEnd. Problem solved!

Cas Smiley

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

Junior Devvie




Where's Flender?


« Reply #10 - Posted 2005-01-20 10:46:59 »

Aha, just a silly problem! Thanks!
I was fooled by the fact that the error appeared only with pbuffers.
p.s. here's the indication that I'm new to OpenGL.

Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (108 views)
2017-09-30 02:57:34

theagentd (135 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (239 views)
2017-08-02 12:19:43

cybrmynd (238 views)
2017-08-02 12:18:09

Sralse (252 views)
2017-07-25 17:13:48

Archive (864 views)
2017-04-27 17:45:51

buddyBro (1007 views)
2017-04-05 03:38:00

CopyableCougar4 (1566 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!