Results 1 to 8 of 8

Thread: Generate picture in OpenGL/ Java OpenGL help information

  1. #1
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Generate picture in OpenGL/ Java OpenGL help information

    Hi,

    I try to generate pictures from an OpenGL scene.. I found many examples in the forums archives but coded in C++ that I do not know.

    I actually work with Java and I would like to know if somebody would have a Java code example or knows where I
    could found help.. like a forum for GL4

    Thanks a lot
    Mat

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: Generate picture in OpenGL/ Java OpenGL help information

    Hi !

    If I remeber correct gl4java has a mailinglist where you could try, another way is to sign up to suns Java forums, they are very helpful there (java.sun.com)

    Mikael

  3. #3
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: Generate picture in OpenGL/ Java OpenGL help information

    Hi,

    thanks
    Have you more information about his mailing list ?

    For the java web site I had already tried but it is difficult to get replies concerning OpenGL..

    Mat

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Generate picture in OpenGL/ Java OpenGL help information

    Isn't it pretty much the same though? glReadPixels to grab your image and then save it in whatever format you want

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Generate picture in OpenGL/ Java OpenGL help information

    I think Gavin is right. It should be pretty much the same. Grab the data with glReadPixels and save to the format you want.

    One thing you may have to watch for, however is byte order. If I remember correctly, Java stores everything as big-endian no matter what the underlying architecture is.

    And then there's the question of converting everything to bytes correctly. Java doesn't have pointers so it's not as simple as writing x bytes from the memory address n.

    I haven't worked with the file stream objects too extensively in Java, but I would think there would be some sort of binary file writer that would let you handle the conversion, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

  6. #6
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: Generate picture in OpenGL/ Java OpenGL help information

    Hi,

    I have two questions more:

    In java, I declare a table of Long for taking the values gave by glReadPixel. I do not understand if this is bytes values that are stocked in the table.You talk about convertion to Bytes. Can you explain that ?

    And how can I set up the size of my table ?

    Thanks a lot
    Mat

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Generate picture in OpenGL/ Java OpenGL help information

    At almost the lowest level, everything can be thought of as bytes. (At the absolutely lowest level is bits, but I have never seen any API that lets you write individual bits to a file before so we'll just ignore that for now...)

    A long in Java is made up of 4 bytes if I remember correctly. In C/C++ if you want to write those exact bytes to a file you do something like...

    long n = 1;

    fwrite(file, &n, 4);

    The bytes that would get written would depend on weather the system was little-endian or big-endian. Intel/AMD chips for instance are little endian and so if you were to look at the above file in a hex editor you would see bytes like so...

    Byte 0: 0x01
    Byte 1: 0x00
    Byte 2: 0x00
    Byte 3: 0x00

    On a big-endian system it would be

    Byte 0: 0x00
    Byte 1: 0x00
    Byte 2: 0x00
    Byte 3: 0x01

    So now you have the problem that you are working with Java, which is strongly typed. So far as I know, you can't just cast a long to a byte array. You can mask out the individual bytes by doing something like so...

    long n = 10;
    byte b0;
    byte b1;
    byte b2;
    byte b3;
    b3 = (byte)(n & 0xFF);
    b2 = (byte)((n & 0xFF00) >> ;
    b1 = (byte)((n & 0xFF0000) >> 16);
    b0 = (byte)((n & 0xFF000000) >> 24);

    But that seems like a lot of work, so I'd look for some class that lets you do the conversion from different data types to a byte array before doing that. I would think one would have to exist.

    All the stuff up to this point is mainly going to apply to writing the file format headers.

    For getting the pixel data, you should be getting a byte array rather than a long array so you don't have to do the long to byte conversions all over. RGB image formats tend to have 1 byte for each component. (e.g. if you got a byte array for 1 pixel of an RGB format, you'd have 3 bytes returned, the first R, second G, third B)

    So... with all that in mind, it seems to me that writing an image file reader/writer in Java is a bit more challenging than in C/C++. If you want to attempt to do so, I'd recommend looking at a fairly simple format like TGA first. www.wotsit.org has the full specification for how the bytes should be written to a file for that and many other formats.

    If you don't feel up to trying all that yourself, there may already be libraries someone has written that you could use.

    Whew... this is getting longer than I originally intended. It's easy to see why I much prefer C/C++ to Java when it comes to low-level graphics programming...
    Deiussum
    Software Engineer and OpenGL enthusiast

  8. #8
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: Generate picture in OpenGL/ Java OpenGL help information

    Hi ,

    thank you very much for your explanation...
    it is getting more clear now..

    Mat

Similar Threads

  1. Loading A Picture in Opengl??
    By Ehsan_Liverpool in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-10-2011, 05:06 AM
  2. Perfect OpenGL picture wanted
    By Andrew Polar in forum OpenGL: Windows
    Replies: 1
    Last Post: 09-13-2004, 08:57 AM
  3. How about picture in OpenGL...
    By El_Segador in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-03-2003, 04:23 PM
  4. Generate heightmap from a picture?
    By Ninja in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 01-11-2003, 05:10 AM
  5. how to save an opengl picture as a .bmp
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-09-2000, 06:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean