LWJGL
May 23, 2012, 03:39:33 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Noob question: How to load an image from disk for use by glDrawPixels()?  (Read 409 times)
habageda
Newbie
*
Posts: 2


« on: January 13, 2012, 02:19:10 »

 Hello,

i'm just starting to explore LWJGL and want to try it using for making an isometric 2D game.

My general question is how i can load an image from disk and display it with glDrawPixels(). glDrawPixels() is straight forward enough but it's all these pixel formats and types i get confused about. I created a picture with Paint.NET with some transparent parts and saved it as .png image with pixeldepth 32. Now if i load this imagedata into memory, what format/type is it in? Furthermore, what format/type must the screenpixels have to properly display the image or is this irrelevant?

I realised that i could also use a quad and project the image as a texture on it. This has the advantage in that i can load the image easily as a texture with the Slick-util library (i haven't found a tool in Slick-util that can load images into memory). However, it seems to me that displaying images as a textured quad is slower than glDrawPixels() since it can be rotated, scaled and translated. This is why i thought i use glDrawPixels() which also seems the more natural thing to do when creating isometric 2D games.

Can somebody help me?

Cheers,

-Harry
Logged
delt0r
Newbie
*
Posts: 25


« Reply #1 on: January 13, 2012, 07:04:08 »

The proper way to draw images in opengl is with a textured quad. Its not slow. I have been told that glDrawPixels can be slow. I have not tested this however.

As for image formats, when you bind your texture you tell opengl what that format is. I currently use TWLs PNGLoader than loads the data directly into a byte buffer and this will give a RGB or RGBA pixel format (unsigned byte per component). IIRC slick uses this too. However getting the data out of a Buffered Image that I loaded with ImageIO is not so hard. You just need to create a image in the right format and then get the rasters. However this requires a bit more memory thrashing. There are some examples on the lwjgl wiki of how to do this.

hope this helps
Cheers
Logged
habageda
Newbie
*
Posts: 2


« Reply #2 on: January 13, 2012, 13:43:47 »

Thx deltOr,

i will try the texture approach. Maybe i'll later try to use glDrawPixels() just for fun... Grin

Cheers!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!