⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readimage.c

📁 OpenGL学习资料
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <GL/gl.h>GLubyte*readImage( const char* filename, GLsizei* width, GLsizei *height ){    int       n;    GLubyte*  pixels;    FILE* infile = fopen( filename, "rb" );    if ( !infile ) {	fprintf( stderr, "Unable to open file '%s'\n", filename );	return NULL;    }    fread( width, sizeof( GLsizei ), 1, infile );    fread( height, sizeof( GLsizei ), 1, infile );    n = 3 * (*width) * (*height);    pixels = (GLubyte *) malloc( n * sizeof( GLubyte ));    if ( !pixels ) {	fprintf( stderr, "Unable to malloc() bytes for pixels\n" );	return NULL;    }    fread( pixels, sizeof( GLubyte ), n, infile );        fclose( infile );    return pixels;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -