Menu Home

jpeg转换OpenGL Texture


jpeg转换OpenGL Texture

#include <stdio.h>
#include <unistd.h>
#include <jpeglib.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glut.h>

void LoadJpgTextureGL(char *file)
{
FILE *jpegFile;
int sizebuf;
unsigned char* buffer;
unsigned char* texturebuf;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);

if((jpegfile = fopen(file,"rb"))==NULL)
{
    perror("fopen jpeg");
    return; 
}
jpeg_stdio_src(&cinfo,jpefile);
jpeg_read_header(&cinfo,TRUE);
jpeg_start_decompress(&cinfo);

sizebuf = cinfo.output_width * cinfo.output_components;
buffer = (unsigned char *)malloc(sizebuf);
texturebuf = (unsigned char *)malloc(sizebuf * cinfo.output_height);
unsigned char *tempjpg = texturebuf;
while(cinfo.output_scanline < cinfo.output_height)
{
    jpeg_read_scanlines(&cinfo,&buffer,1);
    memcpy(texturebuf,buffer,sizebuf);
    texturebuf +=sizebuf;
}
texturebuf = tempjpg;
/*do something .eg: glTexImage2D()*/

jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);

free(buffer);
fclose(jpegfile);
}

14 replies

  1. Thank you so much for giving everyone a very nice chance to discover important secrets from this website. It’s usually very lovely and as well , full of a good time for me and my office peers to visit your website at a minimum three times weekly to learn the latest stuff you have. And indeed, I’m also certainly contented for the powerful tricks you give. Some 2 areas in this article are rather the simplest we have all had.

  2. Needed to post you one little bit of remark to be able to thank you very much as before for the striking thoughts you’ve documented on this website. It is so surprisingly open-handed with people like you giving freely just what a few people would’ve marketed as an e book to make some dough for themselves, specifically now that you might well have done it in the event you decided. These suggestions likewise acted to become a great way to comprehend some people have the identical dreams much like my own to find out significantly more with reference to this matter. I think there are thousands of more fun periods ahead for many who scan through your blog post.

  3. Thanks for each of your effort on this website. My mother enjoys managing internet research and it is simple to grasp why. We learn all of the powerful means you deliver helpful tips and tricks by means of the website and therefore improve participation from some others on this issue then our own simple princess is truly studying a lot of things. Take pleasure in the remaining portion of the new year. You are always performing a great job.

  4. I intended to post you this little word in order to give many thanks over again for the amazing strategies you’ve documented here. It has been simply shockingly open-handed with you to supply without restraint just what most people could have marketed as an e-book in order to make some dough for their own end, most importantly seeing that you could possibly have tried it in case you decided. The points additionally worked like a good way to realize that the rest have the identical interest really like mine to understand more when it comes to this condition. I believe there are a lot more pleasurable opportunities ahead for individuals who start reading your site.

  5. I would like to point out my passion for your kind-heartedness for those individuals that absolutely need help with this topic. Your real commitment to passing the solution all around appears to be exceedingly helpful and has continuously empowered many people like me to attain their aims. The invaluable useful information can mean a lot a person like me and far more to my fellow workers. Thanks a ton; from each one of us.

  6. I am also writing to make you understand what a brilliant experience my cousin’s girl had checking your web page. She came to understand a lot of details, which included how it is like to possess a great coaching style to make many more quite simply fully understand chosen specialized subject areas. You really exceeded our own expected results. Thanks for providing such effective, dependable, educational not to mention unique thoughts on this topic to Jane.

  7. Thank you for your whole labor on this web page. Debby takes pleasure in getting into internet research and it is simple to grasp why. We all know all regarding the powerful means you deliver precious ideas by means of the web site and as well as strongly encourage contribution from people on that content so my child is always discovering so much. Have fun with the remaining portion of the new year. You have been doing a superb job.

  8. I must show my thanks to this writer for bailing me out of this issue. Because of checking throughout the internet and coming across concepts which were not pleasant, I figured my life was done. Living minus the approaches to the issues you have resolved by means of your entire review is a critical case, as well as the ones that would have adversely damaged my career if I had not come across your web blog. Your primary talents and kindness in controlling the whole thing was tremendous. I’m not sure what I would’ve done if I hadn’t discovered such a step like this. I’m able to now relish my future. Thank you so much for the reliable and sensible help. I will not hesitate to propose the website to any individual who should get guidelines about this area.

  9. Thanks a lot for giving everyone a very breathtaking possiblity to read critical reviews from this blog. It can be very great and packed with a great time for me and my office peers to visit your blog at minimum three times in a week to read the newest things you have got. Of course, we’re usually pleased for the stunning suggestions you serve. Some two facts in this posting are particularly the best we’ve had.

  10. Thank you so much for giving everyone such a memorable possiblity to check tips from this website. It is usually so pleasing and packed with a lot of fun for me personally and my office co-workers to search your blog nearly 3 times in one week to read through the new items you have got. Of course, I’m certainly satisfied concerning the effective guidelines served by you. Some two facts in this posting are in reality the most impressive I’ve had.

  11. Thank you a lot for giving everyone an exceptionally terrific chance to read critical reviews from this website. It’s always very brilliant plus jam-packed with amusement for me and my office peers to search your site more than three times in a week to read through the newest items you have. Not to mention, we’re always fascinated with the remarkable solutions served by you. Some 3 points in this posting are rather the best we’ve had.

  12. I must get across my admiration for your kind-heartedness for men who have the need for help on that situation. Your special commitment to passing the solution all-around was especially productive and has in every case encouraged others much like me to attain their objectives. Your warm and helpful help denotes this much to me and much more to my mates. With thanks; from everyone of us.

  13. I want to express some appreciation to the writer just for bailing me out of this condition. Just after looking out throughout the internet and finding recommendations which were not beneficial, I thought my entire life was well over. Living minus the strategies to the difficulties you have resolved by means of your good report is a critical case, as well as the kind that could have in a negative way damaged my entire career if I had not noticed your web site. Your own personal mastery and kindness in taking care of all areas was invaluable. I don’t know what I would’ve done if I had not discovered such a thing like this. I’m able to at this time look forward to my future. Thanks for your time very much for your specialized and effective guide. I won’t be reluctant to refer your web blog to any person who needs to have guidance on this situation.

  14. I want to voice my love for your kindness in support of people that require guidance on this particular subject. Your real dedication to getting the solution all through appeared to be certainly productive and has consistently made many people much like me to arrive at their endeavors. Your helpful key points implies a lot to me and additionally to my colleagues. With thanks; from each one of us.

Leave a Reply

Your email address will not be published.