91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 422KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2021-06-05
  • 語言: 其他
  • 標簽: OpenGL??紋理??貼圖??

資源簡介

本程序為OpenGL紋理貼圖小程序,圖片格式為jpg。代碼中如有疑問請指出,會為你一一解答。

資源截圖

代碼片段和文件信息

#include?“jpegtools.h“

void?DecodeJPG(jpeg_decompress_struct*?cinfo?JPGtexture?*pImageData)
{
????GLint?rowSpan;
????//讀取JPEG文件頭
????jpeg_read_header(cinfo?TRUE);
????//?使用壓縮信息開始解壓縮
????jpeg_start_decompress(cinfo);
????//?讀取圖像大小、像素數據
????rowSpan?=?cinfo->image_width?*?cinfo->num_components;
????pImageData->width???=?cinfo->image_width;
????pImageData->height???=?cinfo->image_height;
????//為pImageData->data分配內存
????pImageData->texels?=?new?GLubyte[rowSpan?*?pImageData->height];
????switch?(cinfo->num_components)
????{
????????case?1:
????????{
????????????????pImageData->internalFormat?=?1;
????????????????pImageData->format?=?GL_LUMINANCE;
????????????????break;
????????}
????????case?2:
????????{
????????????????pImageData->internalFormat?=?2;
????????????????pImageData->format?=?GL_LUMINANCE_ALPHA;
????????????????break;
????????}
????????case?3:
????????{
????????????????pImageData->internalFormat?=?3;
????????????????pImageData->format?=?GL_RGB;
????????????????break;
????????}
????????case?4:
????????{
????????????????pImageData->internalFormat?=?4;
????????????????pImageData->format?=?GL_RGBA;
????????????????break;
????????}
????????default:
????????????break;
????}
????//創建每一行數據的指針
????GLubyte?**?rowPtr?=?new?GLubyte?*[pImageData->height];
????for?(int?i?=?0;?i?height;?i++)
????????rowPtr[i]?=?&(pImageData->texels[(pImageData->height-1-i)*rowSpan]);
????//讀取像素數據
????int?rowsRead?=?0;
????while?(cinfo->output_scanline?output_height)
????{
????????rowsRead+=jpeg_read_scanlines(cinfo&rowPtr[rowsRead]
??????????????????????????????????????cinfo->output_height-rowsRead);
????}
????//?釋放臨時使用的指針
????delete?[]?rowPtr;
????//?解壓縮結束
????jpeg_finish_decompress(cinfo);
}

JPGtexture?*ReadJPEGFromFile(const?char?*filename)
{
????struct?jpeg_decompress_struct?cinfo;
????JPGtexture?*pImageData?=?NULL;???????//存放JPEG數據
????FILE?*pFile;
????//打開文件
????if((pFile?=?fopen(filename?“rb“))?==?NULL)
????{
????????fprintf?(stderr?“error:?couldn‘t?open?\“%s\“!\n“?filename);
????????return?NULL;
????}
????//?定義一個錯誤句柄
????jpeg_error_mgr?jerr;
????//解壓縮信息對象指向錯誤句柄
????cinfo.err?=?jpeg_std_error(&jerr);
????//?初始化解壓縮對象
????jpeg_create_decompress(&cinfo);
????//指定數據源
????jpeg_stdio_src(&cinfo?pFile);
????//分配內存,用于存放數據
????pImageData?=?(JPGtexture*)malloc(sizeof(JPGtexture));
????//?進行解壓縮
????DecodeJPG(&cinfo?pImageData);
????//?釋放內存
????jpeg_destroy_decompress(&cinfo);
????fclose(pFile);
????//?返回已經解壓縮后的數據
????return?pImageData;
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-14?13:16??JPEG_texture\
?????文件??????427514??2016-10-11?13:18??JPEG_texture\car.jpg
?????文件?????????287??2016-10-10?13:58??JPEG_texture\Identity.fp
?????文件?????????327??2016-10-10?13:57??JPEG_texture\Identity.vp
?????文件????????2756??2016-10-11?14:26??JPEG_texture\jpegtools.cpp
?????文件?????????444??2016-10-11?14:24??JPEG_texture\jpegtools.h
?????文件????????5386??2016-10-11?14:20??JPEG_texture\main.cpp
?????文件?????????307??2016-10-11?13:25??JPEG_texture\Rectangle.pro

評論

共有 條評論