Loading jpeg images in OpenGL

19 views
Skip to first unread message

holm.h...@gmail.com

unread,
Apr 25, 2021, 6:50:55 AM4/25/21
to fltk.general

Hi,

I am to load and draw a jpeg image in OpenGL.

Does any have routines for loading the jpeg ? Do fltk have code for that ?

Best regards
Håvard

Albrecht Schlosser

unread,
Apr 25, 2021, 9:40:16 AM4/25/21
to fltkg...@googlegroups.com
On 4/25/21 12:50 PM holm.h...@gmail.com wrote:

> I am to load and draw a jpeg image in OpenGL.
>
> Does any have routines for loading the jpeg ? Do fltk have code for that ?

FLTK has classes that load "all sorts" of images

https://www.fltk.org/doc-1.4/classFl__Image.html

For jpeg see:
https://www.fltk.org/doc-1.4/classFl__JPEG__Image.html

If you wonder how to access the image data to use it for drawing in
OpenGL the following two HowTo's may be helpful:

https://www.fltk.org/articles.php?L466
https://www.fltk.org/articles.php?L468

The latter describes the opposite but maybe it can give you some clues
as well.

For drawing images in OpenGL I can't help.

Ian MacArthur

unread,
Apr 25, 2021, 10:54:09 AM4/25/21
to fltkg...@googlegroups.com
On 25 Apr 2021, at 11:50, holm.haavard wrote:

I am to load and draw a jpeg image in OpenGL.

Does any have routines for loading the jpeg ? Do fltk have code for that ?


Check Greg’s examples - probably starting with this one:


Should be easy to go from there to something that works as you want.



Greg Ercolano

unread,
Apr 25, 2021, 12:09:37 PM4/25/21
to fltkg...@googlegroups.com
    Yes, good call to use texture mapped rectangles.

    Also, I think openGL still has a "bit blit" function that lets one slap a rectangle
    of pixels directly from Fl_JPEG_Image's RGB buffer to the openGL screen using
    glDrawPixels(). Be sure to get the pixel format right when using that, to ensure
    RGB byte ordering of glDrawPixels() is set to match the jpeg image buffer's
    data format.

    The nice thing about texturemapping the image is you get image zoom for
    free; just move the rectangle around as needed. It even will integrate into
    your openGL scene properly in 3D. Just keep the texture rectangle pointed
    at the camera.
Reply all
Reply to author
Forward
0 new messages