Hello,
I'm updating CrackArt's ViewImage dialog box with a new frame that uses OpenGL to display images.
The purpose of this new frame was to use OpenGL to display the image very fast and to be able to zoom, pan and fit using only the GPU.
CrackArt includes a software renderer, which updates the image in this dialog box. For this purpose it includes a small paint button that draws squares in the image. When a square is painted, only the damaged rectangle is updated to GL. This is very useful for painting applications or when an image is updated frequently by another process (rendering, texture synthesis, filters).
Please let me know if you find any bugs or issues with this frame. I have only tested it in Windows, so it would be interesting to hear if this works on other platforms.
Released under wxWidgets license.
Icons by : FAMFAMFAM.COM : http://www.famfamfam.com/lab/icons/silk/
Thank you,
Diego
Mouse Events
Left Mouse click : Copies to the clipboard the mouse position and color (see template)
Left Mouse click on Paint mode : Paints a small square in the image (see paint)
Alt + Middle mouse drag : Pans the image
Alt + Right mouse drag : Zooms the image
Wheel : Zooms the image in 2x and 0.5x intervals.
Toolbar
Save : Saves the image to file.
Clone : Opens a new frame with a clone of the image.
Red : Toggle display of red channel
Green : Toggle display of green channel.
Blue : Toggle display of blue channel.
Alpha : Displays only the alpha channel in grayscale.
Mono : Displays the output in monochromatic.
Background : Displays a checker background to show transparency.
Reload : Reloads the image from disk
Fit Height : Fits the image in the screen by height
Fit Width : Fits the image in the screen by width
Fit Both : Fits the imabe in the screen by both width and height
1:1 : Zooms the image to actual pixel size and centers it
Zoom In : Zooms 2x
Zoom Text : Zooms by user input
Zoom Out : Zoom 0.5x
Filter : Applies Nearest Filtering to the image.
Developer Status Bar
This status bar might be useful only for developer:
X : X Position
Y : Y Position
RGBA : Text window with the color at X,Y pixel
Template : Displays a dialog box with a template to copy the pixel info to the clipboard.
Paint : Activates paint mode.
Restrictions
Requires OpenGL 2.0 with support for non power of 2 images.
If this fails, the image will look white.'
Edit
20090814 : Updated source code to support unicode.
ViewImageGLFrame
ViewImageGLFrame
- Attachments
-
- ViewImageGL.zip
- ViewImageGL source code.
- (34.72 KiB) Downloaded 264 times
Last edited by ScEngMan on Sat Aug 15, 2009 12:12 am, edited 1 time in total.
Diego,
I was looking at your code and it works really good.
I’m new to wxwidgets and opengl and was wondering if you could explain what is the reason or advantage of using your opengl class.
I could just pass unsigned char * of the image to glTexImage2D, right ?
Also another question regarding glTexImage2D, is it the same if a pass GL_UNSIGNED_BYTE or GL_FLOAT
I ask because I’m creating a raytracer and I’m using floats and was wondering if there is any advantage converting to GL_UNSIGNED_BYTE
Thanks,
Guillermo Leal.
I was looking at your code and it works really good.
I’m new to wxwidgets and opengl and was wondering if you could explain what is the reason or advantage of using your opengl class.
I could just pass unsigned char * of the image to glTexImage2D, right ?
Also another question regarding glTexImage2D, is it the same if a pass GL_UNSIGNED_BYTE or GL_FLOAT
I ask because I’m creating a raytracer and I’m using floats and was wondering if there is any advantage converting to GL_UNSIGNED_BYTE
Thanks,
Guillermo Leal.
Hola Guillermo,
Thank you for your comments about the ViewImage frame.
I developed the ViewImageFrame to display images in a 3D application, and it's also the main frame where the raytracer outputs the image it's rendering. Before working with OpenGL I tried to use the DC and I was having a lot of refreshing problems because I had to redraw the whole canvas every time a tile was rendered.
The main advantage of using OpenGL is that it takes care of things like redraw, zoom, filtering, etc. For example, zooming is just a matter of changing the frustum... and since the image is in the GPU, zooming and panning are very very fast.
A disadvantage I saw is that this GL code needs a graphic card that supports non power of two images (say, 800 x 600). In a newer version I haven't posted here I fixed this issue by using 32 x 32 tiles that get damaged and OpenGL refreshes them. This allows this frame to work with graphic cards that don't support power of two images.
Another issue I'm having now is with multi-threaded rendering. When a scene is being rendered by two processors, and both processors update the ViewImageCanvas at the same time, sometimes I miss some raytraced tiles.
My raytracer also renders float colors, but I convert them to unsigned char before saving them to a buffer.. but I would like to keep them as float as long as possible too to be able to save 32 bits per channel images.
The main advantage of keeping your images as float* and uploading a float* array to GL is that you don't have to convert them to unsigned char *, a step that takes a lot of time... However, uploading the images to the GPU also takes time, and probably the GPU converts them to unsigned char * before displaying them... If you try this, please let me know if uploading them as float* is faster.
I will post soon here my newer code, the one that uses 32 x 32 tiles.
Thanks,
Diego A. Castano
Thank you for your comments about the ViewImage frame.
I developed the ViewImageFrame to display images in a 3D application, and it's also the main frame where the raytracer outputs the image it's rendering. Before working with OpenGL I tried to use the DC and I was having a lot of refreshing problems because I had to redraw the whole canvas every time a tile was rendered.
The main advantage of using OpenGL is that it takes care of things like redraw, zoom, filtering, etc. For example, zooming is just a matter of changing the frustum... and since the image is in the GPU, zooming and panning are very very fast.
A disadvantage I saw is that this GL code needs a graphic card that supports non power of two images (say, 800 x 600). In a newer version I haven't posted here I fixed this issue by using 32 x 32 tiles that get damaged and OpenGL refreshes them. This allows this frame to work with graphic cards that don't support power of two images.
Another issue I'm having now is with multi-threaded rendering. When a scene is being rendered by two processors, and both processors update the ViewImageCanvas at the same time, sometimes I miss some raytraced tiles.
Yes, you can specify the type of data you have with the two last arguments in glTexImage2D. GL_UNSIGNED_BYTE when you have an unsigned char * image, and GL_FLOAT if you are using float *.I could just pass unsigned char * of the image to glTexImage2D, right ?
My raytracer also renders float colors, but I convert them to unsigned char before saving them to a buffer.. but I would like to keep them as float as long as possible too to be able to save 32 bits per channel images.
The main advantage of keeping your images as float* and uploading a float* array to GL is that you don't have to convert them to unsigned char *, a step that takes a lot of time... However, uploading the images to the GPU also takes time, and probably the GPU converts them to unsigned char * before displaying them... If you try this, please let me know if uploading them as float* is faster.
I will post soon here my newer code, the one that uses 32 x 32 tiles.
Thanks,
Diego A. Castano
I've just tested the application with a 1959 x 1428 JPEG image and it displays and behaves correctly.Can not display any jpeg pictures
Are you sure your video card supports OpenGL 2.0 with non power of 2 images? You can test that with a 512 x 512 jpeg image, if it works, and a 800 x 600 jpeg image doesn't, then your video card doesn't support non power of 2 images.