Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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  
  A few questions about Screenshot class usages  (Read 1505 times)
0 Members and 1 Guest are viewing this topic.
Offline hortiz

Junior Newbie





« Posted 2006-01-12 14:13:31 »

Hi,

I want to generate an image from a  GLPBuffer instance, and I've managed to do it using the new Screenshot class, with the writeToFile method.

My problem is that I want an "offscreen" generation, i.e. I don't want to display any JOGL widgets, but if I don't add the GLCanvas in my main frame pane, the init() and display() methods of the GLEventListener are never called...

How should I do this ?
Thanks
Offline xicon

Senior Newbie





« Reply #1 - Posted 2006-01-12 15:20:14 »

Hi

If you create a GLPBuffer somewhere in your program at the point you want to take the screenshot using the GLDrawableFactory, then add the same GLEventListener as you would for your GLCanvas and then call your offscreen to call display() then it should work. Also you would put the Screenshot code in your display() method,

Code something like this should work, where glEventListener is your own GLEventListener:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
offScreen = true;
offScreenCanvas = GLDrawableFactory.getFactory().createGLPbuffer(cap, new DefaultGLCapabilitiesChooser(), width, height, null);
offScreenCanvas.addGLEventListener( glEventListener );

outputFile = new File( dumpname );
// this causes all the events to fire
// Also screen capture is done inside the Display loop.
offScreenCanvas.display();

// tidy up the event listener - upto you to do this
offScreenCanvas.removeGLEventListener(this);
offScreenCanvas.destroy();


Something like this in your display method for glEventListener:

1  
2  
3  
4  
5  
6  
7  
8  
if ( offScreen ) {
  try {
       Screenshot.writeToFile( outputFile, screenDim.width, screenDim.height );
  }
  catch( IOException ioe ) {
       System.err.println( "Error Creating File: " + ioe.getMessage() );
  }
}


Hope this is some help

Mike
Offline hortiz

Junior Newbie





« Reply #2 - Posted 2006-01-12 16:18:34 »

Thanks Mike

It works fine now !

 Smiley



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

Senior Newbie





« Reply #3 - Posted 2006-05-08 17:40:00 »

I used the code by Mike, but I only get a black image as result.

My glEventListener's display method is called by my GLPbuffer object und the jpg file is written to disc by the ScreenShot class with the correct image width and height. When testing with my GLCanvas object and the Screenshot class, the image is all right. Furthermore I set the flag setDoubleBuffered for my GLPbuffer to false. GLDrawableFactory.getFactory().canCreateGLPbuffer() returns true.

Any suggestions why my image is black only?

Thanks,
Jens
Offline xicon

Senior Newbie





« Reply #4 - Posted 2006-05-09 09:11:56 »

If the image is alright when your using GLCanvas it should work fine for pbuffer.

I am not sure what your doing exactly, but there are two ways of doing it that I think should work:

The way I have posted before where you add your glEventListener to the pbuffer, then call display, make sure the Screenshot.writeToFile() function is inside your GLEventListener.display().

The other option is to create your pbuffer with the right capabilities, make the context of the pbuffer current ( pbuffer.getContext().makeCurrent() ) for the thread your working on then call your glEventListener.init( pbuffer ), followed by glEventListener.display( pbuffer ), since this is not using the GLEventListener rendering loop, you can have the Screenshot.writeToFile() outside of the display() and in the same part of the code as the pbuffer creation. You will have to release the context ( pbuffer.getDrawable().release() ) after you have done the writeToFile() though.

If neither of these ways work, I would suggest you post some code, such as your glEventListener and also the code that creates the pbuffer etc. Then someone with more knowledge might be able to point you in the right direction.

I hope this helps.

Mike
Offline jensall

Senior Newbie





« Reply #5 - Posted 2006-05-09 14:29:55 »

Thanks for your comments.

Well, I tried once more with a real simple test application and a basic scene. Then it worked!
When I looked again at my rather complicated application with a camera, I got it working adding
Quote
   GLU glu = new GLU();
   gl.glMatrixMode(GL.GL_PROJECTION );
   gl.glLoadIdentity();
   double aspectRatio = (double)drawable.getWidth() / (double)drawable.getHeight();
   glu.gluPerspective(60.0, aspectRatio, 1.0, 800.0);   
into the init method which was only placed in the reshape method before.

Now testing to export a quad with a texture, it works for the simple test application but with the complicated application I get the quad drawn filled with the currently set color.
I've attached my init and display method.

Quote
   public void init ( GLAutoDrawable drawable )
   {

      GL gl = drawable.getGL();

      gl.glShadeModel( GL.GL_SMOOTH ); // Enable Smooth Shading
      gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); // Background color
      gl.glClearDepth( 1.0f ); // Depth Buffer Setup
      gl.glEnable( GL.GL_DEPTH_TEST ); // Enables Depth Testing
      gl.glDepthFunc( GL.GL_LEQUAL ); // The Type Of Depth Testing To Do
      gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );
      
      GLU glu = new GLU();
      gl.glMatrixMode(GL.GL_PROJECTION );
       gl.glLoadIdentity();
       double aspectRatio = (double)drawable.getWidth() / (double)drawable.getHeight();
       glu.gluPerspective(60.0, aspectRatio, 1.0, 800.0);      
   }

   public void display ( GLAutoDrawable drawable )
   {
      final GL gl = drawable.getGL();      
      
      gl.glEnable( GL.GL_DEPTH_TEST );
      gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();

      GLU glu = new GLU();
      glu.gluLookAt( eyePoint.x, eyePoint.y, eyePoint.z, targetViewPoint.x,
            targetViewPoint.y, targetViewPoint.z, upVector.x, upVector.y,
            upVector.z );
      
      if ( newTexture )
      {
         System.out.println( "loading new texture" );
         newTexture = false;

         if ( texture != null )
         {
            texture.dispose();
            texture = null;
         }

         try
         {
            file = new File("image.jpg" );            
            texture = TextureIO.newTexture( file, true );
         }
         catch ( IOException e )
         {
            e.printStackTrace();
            return;
         }
      }

      if ( texture != null )
      {
         texture.enable();
         texture.bind();
         gl.glTexEnvi( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,
               GL.GL_REPLACE );
         TextureCoords coords = texture.getImageTexCoords();

         gl.glBegin( GL.GL_QUADS );
         gl.glTexCoord2f( coords.left(), coords.bottom() );
         gl.glVertex3f( 0, 0, 5 );
         gl.glTexCoord2f( coords.right(), coords.bottom() );
         gl.glVertex3f( 50, 0, 5 );
         gl.glTexCoord2f( coords.right(), coords.top() );
         gl.glVertex3f( 50, 50, 5 );
         gl.glTexCoord2f( coords.left(), coords.top() );
         gl.glVertex3f( 0, 50, 5 );
         gl.glEnd();
         texture.disable();
      }
      
      if ( exportImage )
      {         
         File outputFile = new File( "c:\\temp\\output\\export.jpg" );
         System.out.println( "exporting screenshot to: " + outputFile.getName() );
         System.out.println("using: " + drawable.toString());
         try
         {
            Screenshot.writeToFile( outputFile, drawable.getWidth(), drawable.getHeight() );
         }
         catch ( GLException e )
         {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         catch ( IOException e )
         {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         exportImage = false;
      }
   }
Offline xicon

Senior Newbie





« Reply #6 - Posted 2006-05-11 09:40:51 »

Does this code display a textured quad on a GLCanvas?

I haven't got any experience of doing offscreen renderering of textured quads.

However there should be someone on these forums who can help you, or at least point you in the right direction.
Offline jensall

Senior Newbie





« Reply #7 - Posted 2006-05-11 09:57:27 »

yes, that's exactly what I do not really understand.
Using the glCanvas the texture is drawn, but using the pBuffer it is not...
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.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
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!