Show Posts
|
|
Pages: [1]
|
|
2
|
Java Game APIs & Engines / JOGL Development / Offscreen rendering: doing a little better
|
on: 2003-11-24 06:55:17
|
Hi, I would be happy to get a couple of opinions on my previous post, but in the act of desperation, I started everything from scratch working from the PBDemo posted by Ken Russell or GKW - sorry don't remember. It now kind of works (not really). Here are the problems. 1. I seem to be limited to powers of 2 for sizes. I seem to recall from previous posts that this may not need to be the case. Is this so? Does it depend on my video card? Are there plans to change that? (Java3D - something I've been using, but grown to dread - does not have this limitation.) 2. My second, more significant problem is summarized on the following page: http://www.geocities.com/dolachin/offscreen.htmlBasically, something goes very wrong at higher resolutions. Once again, thank you for all the help. Dola
|
|
|
|
|
3
|
Java Game APIs & Engines / JOGL Development / Offscreen rendering revisited
|
on: 2003-11-24 04:50:47
|
|
Hi,
I'm revisiting a topic from three months ago. I've been trying to incorporate the advice I got at this forum at get it to work on my own - and failed!!!
I'm working on a scientific application which shows the evolution of a shape. Every once in a while I want to be able to snap a picture of what's going on. I don't want to overload you, potential helpers, with code so I will just present the code for my takeAPicture procedure (with comments) and may be you will be able to spot something. I am very happy to post more code.
Many thanks in advance for any advice.
public BufferedImage takeAPicture(int inWidth, int inHeight) {
if (myOffScreenBuffer == null) { // class member elem GLCapabilities pbCaps = new GLCapabilities(); pbCaps.setDoubleBuffered(false); myOffScreenBuffer = myCanvas3D.createOffscreenDrawable(pbCaps, inWidth, inHeight); myOffScreenBuffer.addGLEventListener(new OffScreenGLEventListener());
// I have a hard time getting init() to be called in // OffScreenGLEventListener. I have to resize the live // window, call takeAPicture again, and only then it // gets called.
}
BufferedImage pbImage = new BufferedImage(inWidth, inHeight, BufferedImage.TYPE_3BYTE_BGR); DataBufferByte dbByte = (DataBufferByte) pbImage.getRaster().getDataBuffer(); myOffScreenBuffer.display();
myOffScreenBuffer.getGL().glReadPixels(0, 0, inWidth, inHeight, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, dbByte.getData());
return pbImage; // returns nothing but black pixels }
Would you like to see my OffScreenGLEventListener?
|
|
|
|
|
4
|
Java Game APIs & Engines / JOGL Development / Re: Off-screen rendering - help me get started
|
on: 2003-09-29 19:28:47
|
|
Thank you so much for addressing each one of the questions. You guys are great!
One more though (since I don't seem to get this to work in the context of my application).
Does the canvas and the pbuffer each need its own GLEventListener you can they share one? Especially in my case where the drawing is presumably the same.
Thanks.
|
|
|
|
|
5
|
Java Game APIs & Engines / JOGL Development / Re: Off-screen rendering - help me get started
|
on: 2003-09-28 09:07:21
|
|
Wow, thank you very much for the post! I'm sorry I only got to testing it yesterday, got sidetracked by an urgent project.
I tested the code on my system and it works. I was able to save the scene as an image which is precisely what I want!
But a whole lot of new questions arose and I would like to describe one of my applications in some detail so I can my questions in context. I have an application which has live 3d rendering so I have a bona fide canvas in a real window, etc. There are massive vertex list which were constructed with the canvas as the GLDrawable input. Now every once in a while (often!) I have a need to "take a picture" of the scene, usually with identical view and projection settings but with different aspect ration and dramatically different resolutions. So that's the situation and here are my questions:
1. Do I have to regenerate the lists with the pbuffer as the GLDrawable? 2. If yes, can I change the dimensions of the pbuffer without regenerating the lists? It would be a significant drag on the resources if I had to regenerate the lists every time I change the resolution. 3. Can I have my regular canvas createOffscreenDrawable()? 4. What does it mean that "PBuffers are lazily created"? 5. Finally, do I have to have a GLEventListener? Since I have my GLDrawable (the pbuffer!) can I just give gl commands?
Once again, very many thanks. It's beginning to look like the switch to Jogl will actually work!!!
Dola
|
|
|
|
|
8
|
Java Game APIs & Engines / JOGL Development / Re: Off-screen rendering - help me get started
|
on: 2003-09-19 02:08:42
|
|
Thanks for the reply.
But would that let me draw at a resolution different from that of the canvas?
(Is this question appropriate for a new thread? Maybe an example which renders offscreen and saves the result to an image - which can then be converted to java's buffered image - would be very useful and appreciated!)
|
|
|
|
|
9
|
Java Game APIs & Engines / JOGL Development / Re: Off-screen rendering - help me get started
|
on: 2003-09-18 05:40:32
|
|
Oh, I must be color blind, I didn't realizer that "here" was a link.
Thanks for posting the demo. I'm afraid that I kind of miss the point. You seem (although I'm not sure that is the case) to draw to an offscreen buffer, but then display that buffer in the gl window. Am I correct? And if so, can you point out the four or five critical lines of code where the connection the offscreen buffer and the onscreen buffer is made. If I'm correct, that this is a very very cool feature.
Actually, I'm afraid that I may have been to vague when I said "off-screen rendering". What I really want to do is to get an image out of the hole thing. I want to do the rendering on a web server which may not even have a video card and output an image. I apologize profusely if I caused you to answer a wrong question or if you answered the right question and I totally missed the answer.
I appreciate your time,
Dola
|
|
|
|
|
18
|
Java Game APIs & Engines / JOGL Development / Re: GL_BACK material properties.
|
on: 2003-09-09 15:26:17
|
|
Hi,
I would very much like to post more code, but I'm not quite sure what part of my program to quote. If I have
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) );
and
gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) );
right next to each other and green works but red doesn't, can you give me an idea of I might be doing wrong?
Thanks!
Pavel
|
|
|
|
|
20
|
Java Game APIs & Engines / JOGL Development / GL_BACK material properties.
|
on: 2003-09-08 03:45:53
|
Hi, Thanks for helping me figure out the previous question about lighting. I'm still having trouble giving the back side of polygons a color different from the front side. The same sphere (with fixed lighting!) with half the triangles missing so you can see through can be found. http://www.geocities.com/bura3no/index.htmThe relevant code is here: gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) ); gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) ); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, Color.BLACK.getComponents(null)); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, Color.WHITE.getComponents(null) ); gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); gl.glBegin(GL.GL_TRIANGLES); for (int t = 0; t < myMesh.pGetNumberOfElements()/2; t++) { Element elem = myMesh.pGetElement(t); for (int v = 0; v < elem.pGetNumberOfNodes(); v++) { VDouble x = myMesh.pGetX(elem.pGetNode(v)); VDouble n = normals[elem.pGetNode(v)]; gl.glNormal3d(n.pGet(0), n.pGet(1), n.pGet(2)); gl.glVertex3d(x.pGet(0), x.pGet(1), x.pGet(2)); } } gl.glEnd(); } gl.glEndList();
|
|
|
|
|
22
|
Java Game APIs & Engines / JOGL Development / Re: Does lighting work?
|
on: 2003-09-07 03:41:51
|
|
Hi,
I'll start in little specs. I have a concept of a mesh which consists of triangles. The mesh knows how to calculate the normals and I am assured that the normals are correct.
Actually, there only difference between the two spheres on the image is GL_FLAT vs. GL_SMOOTH and I would argue that even on the left GL_FLAT image the shading is wrong.
gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, myAmbientColorBack.getComponents(null) ); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, myAmbientColorFront.getComponents(null) );
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, ZERO );
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, Color.WHITE.getComponents(null) ); gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
for (int t = 0; t < myMesh.pGetNumberOfElements(); t++) { Element elem = myMesh.pGetElement(t); gl.glBegin(GL.GL_TRIANGLES); for (int v = 0; v < elem.pGetNumberOfNodes(); v++) { VDouble x = myMesh.pGetX(elem.pGetNode(v)); VDouble n = normals[elem.pGetNode(v)]; gl.glVertex3d(x.pGet(0), x.pGet(1), x.pGet(2)); gl.glNormal3d(n.pGet(0), n.pGet(1), n.pGet(2)); } gl.glEnd(); } }
Then elsewhere in my init() I have:
GL gl = inDrawable.getGL();
gl.glClearColor(1f, 1f, 1f, 1f);
gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); gl.glEnable(GL.GL_POLYGON_OFFSET_LINE);
// Lights gl.glEnable(GL.GL_LIGHTING); gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, new float[] { .6f, .6f, .6f, 1f });
myLight0 = new GLUtils.Light(myCanvas3D, // Self-explanatory, really GL.GL_LIGHT0, 0f, 0f, 3f, Color.GRAY, Color.BLACK);
// Uncomment for FLAT. // gl.glShadeModel(GL.GL_FLAT);
Thanks for taking a look at this.
Dola
|
|
|
|
|
23
|
Java Game APIs & Engines / JOGL Development / Does lighting work?
|
on: 2003-09-05 20:44:55
|
Hi, 1. I may be making an OpenGL mistake or it might be a JOGL bug. I am lighting a sphere, composed exclusively of triangles. I compute the normals on my own and I am very confident that my normals are OK. http://www.geocities.com/bura3no/lighting.pngThe figure on the left is GL_FLAT. The figure on the right is GL_SMOOTH. 2. Also, I can't get the back side of my polygons to be a different color from the front side. They both have the same color as GL_FRONT. Are these known issues or should I post some code? Many thanks in advance! Dola
|
|
|
|
|
25
|
Java Game APIs & Engines / JOGL Development / Why require context?
|
on: 2003-09-04 18:11:38
|
|
Hi,
My life has taken me from OpenGL to Java3D and now to Jogl. And I have this question.
The way I've been organizing my code is by letting each object build itself and then sticking it into varous contexts. But with Jogl this seems not possible since any routine that does the building needs to have an instance of the GL class. This causes a couple "problems".
1. I need to build each object several times depending on the context. 2. I can't hide implementation (that fact that I'm using Jogl) since all of my routines have GLDrawable as an argument, and I have always been taught to separate logic from implementation.
Any thoughts?
Dola
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|