JPEG texturing, I need help!!!
I''m writing something that requires me to load up a .jpg image and use it as a texture... I have been unable to find any good libraries to do this, and I really need some help..
So, if anyone would be so kind as to maybe post some code, or point me to a website that I might have missed, I would be very thankful...
-Fredric
Haven''t been able to find any good libraries!? How you looked at DevIL? It is an awesome image loading library (designed with the same syntax as OpenGL).
dont forget imagelib
but at any rate, you should definately think about changing
your image format.. jpeg''s patents just got claimed and
most likely you''ll end up with licensing fees and/or legal
issues...
-eldee
;another space monkey;
[ Forced Evolution Studios ]
but at any rate, you should definately think about changing
your image format.. jpeg''s patents just got claimed and
most likely you''ll end up with licensing fees and/or legal
issues...
-eldee
;another space monkey;
[ Forced Evolution Studios ]
I''ve taken a look at Devil, and it didn''t worked a lot less then when I tried to load up the jpg with a tga loader...
Perhaps a jpg->bmp converter would be a good idea, anyone know a good library for that?
-Fredric
Perhaps a jpg->bmp converter would be a good idea, anyone know a good library for that?
-Fredric
my shadowmapping demo uses a lib that doesn''t require dll''s.
at nehe.gamedev.net -> downloads -> S -> shadowmap v7
at nehe.gamedev.net -> downloads -> S -> shadowmap v7
quote:Original post by FDGaming
I''ve taken a look at Devil, and it didn''t worked a lot less then when I tried to load up the jpg with a tga loader...
Perhaps a jpg->bmp converter would be a good idea, anyone know a good library for that?
-Fredric
DevIL is IMO the best image library out there. Perhaps you should explain your problems with it, because chances are, it is not working well because of something you are doing wrong.
As for a jpg->bmp conversion, you can use just about any image manipulation program for that. The GIMP is an excellent open source program that lets you work with a wide range of image formats, and even Paint lets you load and save .jpg files (load up your JPG, then Save As a bitmap).
Actually, the shadowmapping program was easy to use, and I can get the texture mapping to work just fine with JPEGs now. Thanks for the help.
-Fredric
-Fredric
look at my website, www.freewebz.com/ionware for CMaterial class, there''s a loading function for JPEG in it.
" Do we need us? "
" Do we need us? "
Ok, here''s the code (btw, it''s not my work - tnx to Snake ):
-----------------------------------------------------------------
#include "jpeglib.h"
#pragma comment(lib, "jpeg.lib")
//***************** Prototypes ************************//
// function for loading .jpg
tImage *LoadJPG(const char *strFileName);
// for .jpg decoding and decompression
void DecodeJPG(jpeg_decompress_struct* cinfo, tImage*pImageData);
///////////////////////////////// DECODE JPG ///////////
/* here we decode .jpg */
void DecodeJPG(jpeg_decompress_struct* cinfo, tImage *pImageData)
{
// reads JPG''s header
jpeg_read_header(cinfo, TRUE);
// decompression
jpeg_start_decompress(cinfo);
pImageData->channels = cinfo->num_components;
pImageData->sizeX = cinfo->image_width;
pImageData->sizeY = cinfo->image_height;
int rowSpan = cinfo->image_width * cinfo->num_components;
pImageData->data = ((unsigned char*)malloc(sizeof(unsigned char)*rowSpan*pImageData->sizeY));
unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
for (int i = 0; i < pImageData->sizeY; i++)
rowPtr = &(pImageData->data); <br><br> int rowsRead = 0; <br> while (cinfo->output_scanline < cinfo->output_height) <br> { <br> rowsRead += jpeg_read_scanlines(cinfo, <br> &rowPtr[rowsRead], cinfo->output_height - rowsRead); <br> } <br> <br><br> // finish decompression<br> jpeg_finish_decompress(cinfo); <br>} <br><br><br>///////////////////////////////// LOAD JPG /////////////<br>/* here we load .jpg */<br><br><br>tImage *LoadJPG(const char *strFileName) <br>{ <br> struct jpeg_decompress_struct cinfo; <br> tImage *pImageData = NULL; <br> FILE *pFile; <br> <br> <br> if((pFile = fopen(strFileName, "rb")) == NULL) <br> { <br> MessageBox(g_hWnd, "Loading Failed!", "Error", MB_OK); <br> return NULL; <br> } <br> <br><br> jpeg_error_mgr jerr; <br><br> // Have our compression info object point to the error handler address <br> cinfo.err = jpeg_std_error(&jerr); <br> <br> <br> jpeg_create_decompress(&cinfo); <br> <br> <br> jpeg_stdio_src(&cinfo, pFile); <br> <br> <br> pImageData = (tImage*)malloc(sizeof(tImage)); <br><br> <br> DecodeJPG(&cinfo, pImageData); <br> <br> jpeg_destroy_decompress(&cinfo); <br> <br> fclose(pFile); <br><br> return pImageData; <br>} <br> </i>
-----------------------------------------------------------------
#include "jpeglib.h"
#pragma comment(lib, "jpeg.lib")
//***************** Prototypes ************************//
// function for loading .jpg
tImage *LoadJPG(const char *strFileName);
// for .jpg decoding and decompression
void DecodeJPG(jpeg_decompress_struct* cinfo, tImage*pImageData);
///////////////////////////////// DECODE JPG ///////////
/* here we decode .jpg */
void DecodeJPG(jpeg_decompress_struct* cinfo, tImage *pImageData)
{
// reads JPG''s header
jpeg_read_header(cinfo, TRUE);
// decompression
jpeg_start_decompress(cinfo);
pImageData->channels = cinfo->num_components;
pImageData->sizeX = cinfo->image_width;
pImageData->sizeY = cinfo->image_height;
int rowSpan = cinfo->image_width * cinfo->num_components;
pImageData->data = ((unsigned char*)malloc(sizeof(unsigned char)*rowSpan*pImageData->sizeY));
unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
for (int i = 0; i < pImageData->sizeY; i++)
rowPtr = &(pImageData->data); <br><br> int rowsRead = 0; <br> while (cinfo->output_scanline < cinfo->output_height) <br> { <br> rowsRead += jpeg_read_scanlines(cinfo, <br> &rowPtr[rowsRead], cinfo->output_height - rowsRead); <br> } <br> <br><br> // finish decompression<br> jpeg_finish_decompress(cinfo); <br>} <br><br><br>///////////////////////////////// LOAD JPG /////////////<br>/* here we load .jpg */<br><br><br>tImage *LoadJPG(const char *strFileName) <br>{ <br> struct jpeg_decompress_struct cinfo; <br> tImage *pImageData = NULL; <br> FILE *pFile; <br> <br> <br> if((pFile = fopen(strFileName, "rb")) == NULL) <br> { <br> MessageBox(g_hWnd, "Loading Failed!", "Error", MB_OK); <br> return NULL; <br> } <br> <br><br> jpeg_error_mgr jerr; <br><br> // Have our compression info object point to the error handler address <br> cinfo.err = jpeg_std_error(&jerr); <br> <br> <br> jpeg_create_decompress(&cinfo); <br> <br> <br> jpeg_stdio_src(&cinfo, pFile); <br> <br> <br> pImageData = (tImage*)malloc(sizeof(tImage)); <br><br> <br> DecodeJPG(&cinfo, pImageData); <br> <br> jpeg_destroy_decompress(&cinfo); <br> <br> fclose(pFile); <br><br> return pImageData; <br>} <br> </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement