Advertisement

JPG LOADING PROBLEM =(

Started by May 01, 2001 08:14 AM
8 comments, last by Maniac2001 23 years, 9 months ago
Can anyone tell me how to load a jpg texture (with source)? i tryed this but it dosent work: AUX_RGBImageRec *LoadJPG(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL } File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL } int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[8]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap''s Not Found Quit // textur 1 mipmap if (TextureImage[0]=LoadJPG("Data/matrix.jpg")) { Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); }
Looks like you just took the bitmap loading code out of nehe''s tutorial and replaced some of the BMP''s with JPG''s :-)
Not that easy I''m afraid. You need to find the jpg file format spec and then learn to read binary files etc... You might want to try something easier first. Look at the TGA loader in nehe''s tutorial.
-DeVore
Advertisement
i now know that this was wrong =)
i want to use the code from http://www.ijg.org/
can anyone give me a NeHe based source that uses this libary to load JPGs and place them on a qube?
FYI - I have heard that JPEGSs look like crap in OpenGL as textures due to the way JPEGs are compressed. (I have not tried using them, so I am not positive on this).

You can read the article on them at http://web2.airmail.net/sjbaker1/jpegs_are_evil_too.html

Hope this helps
Roach
Did you know Quake III Arena? This textures are JPGs and they are looking great!!!
So dont say that Jpgs look bad in OpenGL !
=)
Depends on the type of textures you are using: hand drawn or synthetic textures don''t look so good (lots of blocking artifacts), or you have to use a rather low compression ratio. This is because of large unicolored or smooth gradient parts on them, jpeg doesn''t like this. Photorealistic textures, on the other hand, look great wth jpeg, even highly compressed.
Advertisement
no offense bro, but did you seriously think by just renaming the fucntions to have JPG in them that it would work? hehe
HAHA, sorry, i just have to laugh.
made my day as well :D

http://members.xoom.com/myBollux
Hey what a coincidence, that question come just one month after april fool''s day.
(you can find me on IRC : #opengl on undernet)

here is some source from my raycast engine which uses jpeblib-6b to read a JPEG image
into a buffer...

NOTE: the rc_fopen.. etc are my custom functions to handle IO, but mimic fopen, etc exactly... _rcBITMAP is a custom struct which holds the final bitmap data

you need both the jpeglib and header files to compile this.

  int rcrTexture::LoadJPEG(LPSTR fn){	// start up the JPEG 6b system...	struct jpeg_decompress_struct jds;	struct jpeg_error_mgr jerr;	_RCFILE *inFile;	_rcBITMAP rcb;	JSAMPARRAY buffer;	int RowWidth;	// open the file...	if ((inFile = rc_fopen(fn,"rb")) == NULL)	{		return 0;	}	// setup standard error handling...	jds.err = jpeg_std_error(&jerr);	// initialize decompressor	jpeg_create_decompress(&jds);	//specify a file source	jpeg_rcfile_src(&jds ,inFile);	// read the header	jpeg_read_header(&jds,TRUE);//	jpeg_calc_output_dimensions(&jds);	jpeg_start_decompress(&jds);	// setup our final surface...	rcb.dwWidth = jds.output_width;	rcb.dwHeight = jds.output_height;		if (jds.out_color_components == 3)	{		rcb.dwFormat = RCFORMAT_RGB;		rcb.dwBitmapBytes = rcb.dwWidth * rcb.dwHeight * 3;		rcb.lpBitmap = new unsigned char[rcb.dwBitmapBytes];		rcb.lpPalette = NULL;	} else return 0;	// get row_width & make a scan-line buffer	RowWidth = jds.output_width * jds.output_components;	buffer = (*jds.mem->alloc_sarray)		((j_common_ptr) &jds, JPOOL_IMAGE, RowWidth, 1);	BYTE *p = (BYTE *)rcb.lpBitmap, *pb;//	adj = ddsd.lPitch - jds.output_width*2;	while (jds.output_scanline < jds.output_height)	{		jpeg_read_scanlines(&jds,buffer,1);		// write out the scanline			pb = (BYTE *)buffer[0];		for (DWORD x=0;x<jds.output_width;x++)		{			p[0] = pb[x*3];			p[1] = pb[x*3+1];			p[2] = pb[x*3+2]; 			p += 3;		} 		//p += adj;	}	jpeg_finish_decompress(&jds);	jpeg_destroy_decompress(&jds); 	rc_fclose(inFile);	return 1;}  


This topic is closed to new replies.

Advertisement