【OpenGL】===配置与整理OpenGL===

OpenGL官网:https://www.opengl.org/

zlib下载:http://www.zlib.net/

libpng下载:http://www.libpng.org/pub/png/libpng.html

GLEW下载:http://glew.sourceforge.net/index.html

GLFW下载:http://www.glfw.org/download.html

LearnOpenGL-CN:https://learnopengl-cn.readthedocs.io/zh/latest/

OpenGL入门学习http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html

OpenGL 常用函数解析:http://www.tuicool.com/articles/FBR3Ezq

OpenGL Step by Step:http://ogldev.atspace.co.uk/index.html

一步步学OpenGL :http://blog.csdn.net/column/details/13062.html

OpenGL ES 2.0 完全入门(二):矩形、图片、读取显存等:

https://blog.piasy.com/2016/06/14/Open-gl-es-android-2-part-2/

《OpenGL ES编程指南》源代码:http://www.opengles-book.com/samplecode.html

OpenGL原理介绍:http://www.twinklingstar.cn/2015/1532/introduce-to-opengl/#1_OpenGL

三维图像技术与OpenGL基础理论http://blog.csdn.net/yarkey09/article/details/38026413

 

===========================

 

Small Flows

===========================

 

 

 

 

 

【OpenGL Programming On macOS using glfw 】0: Build a Simple OpenGL Program

2016-11-18 09:06 阅读(101) 评论(2)

 

【cocos2d-x 2.x 学习与应用总结】14: 自定义shader绘制混合颜色的矩形

2016-01-25 23:12 阅读(361) 评论(0)

 

【cocos2d-x 2.x 学习与应用总结】13: 借助CCGLProgram实现自定义绘制

2016-01-21 01:42 阅读(309) 评论(0)

 

【cocos2d-x 2.x 学习与应用总结】12: cocos2d-x预定义shader源码

2016-01-20 21:24 阅读(319) 评论(0)

 

【cocos2d-x 2.x 学习与应用总结】11: 理解CCGLProgram

2016-01-20 01:09 阅读(550) 评论(0)

 

【cocos2d-x 2.x 学习与应用总结】10: cocos2d-x自带的shader及其使用

2016-01-19 22:16 阅读(480) 评论(0)

 

【C++ OpenGL ES 2.0编程笔记】1: OpenGL ES 2.0 渲染管线和EGL

2016-01-08 00:46 阅读(535) 评论(0)

 

【C++ OpenGL ES 2.0编程笔记】8: 使用VBO和IBO绘制立方体

2016-01-07 00:54 阅读(1098) 评论(0)

 

【C++ OpenGL ES 2.0编程笔记】5: mipmap

2016-01-05 23:58 阅读(562) 评论(0)

 

【C++ OpenGL ES 2.0编程笔记】4: 纹理贴图-图片叠加效果实现

2016-01-04 21:44 阅读(1630) 评论(0)

 

 

 

 

 

// OpenGL_Test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>

#include <glew.h>
#include "glut.h"

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string>

#include "png.h"
#include "zlib.h"
#include <glfw3.h>


#pragma comment(lib, "glut.lib")
#pragma comment(lib, "glut32.lib")

#pragma comment(lib, "libpng16.lib")
#pragma comment(lib, "zlib.lib")

#pragma comment (lib,"glew32d.lib")

#pragma comment (lib,"glfw3.lib")
#pragma comment (lib,"glfw3dll.lib")


///* Makes pngtest verbose so we can find problems. */
//#ifndef PNG_DEBUG
//#  define PNG_DEBUG 2
//#endif
//
//#if PNG_DEBUG > 1
//#  define pngtest_debug(m)        ((void)fprintf(stderr, m "\n"))
//#  define pngtest_debug1(m,p1)    ((void)fprintf(stderr, m "\n", p1))
//#  define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
//#else
//#  define pngtest_debug(m)        ((void)0)
//#  define pngtest_debug1(m,p1)    ((void)0)
//#  define pngtest_debug2(m,p1,p2) ((void)0)
//#endif
//
//unsigned char* buffer = NULL;
//png_uint_32 width, height;
//int color_type;
//
获取每一行所用的字节数,需要凑足4的倍数
//int getRowBytes(int width){
//	//刚好是4的倍数
//	if ((width * 3) % 4 == 0){
//		return width * 3;
//	}
//	else{
//		return ((width * 3) / 4 + 1) * 4;
//	}
//}
//
//
//void readpng__001(char* name)
//
//{
//
//	// 前边几句是扯淡,初始化各种结构
//
//	FILE* file = fopen(name, "rb");
//
//	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
//
//	png_infop info_ptr = png_create_info_struct(png_ptr);
//
//	setjmp(png_jmpbuf(png_ptr));
//
//	// 这句很重要
//
//	png_init_io(png_ptr, file);
//
//	// 读文件了
//
//	png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND, 0);
//
//	// 得到文件的宽高色深
//
//	int m_width = png_get_image_width(PngPtr, InfoPtr);
//	int m_height = png_get_image_height(PngPtr, InfoPtr);
//
//	int color_type = png_get_color_type(PngPtr, InfoPtr);
//
//	// 申请个内存玩玩,这里用的是c++语法,甭想再c上编过
//
//	int size = m_height * m_width * 4;
//
//	unsigned char* bgra = new unsigned char[size];
//
//	int pos = 0;
//
//	// row_pointers里边就是传说中的rgba数据了
//
//	png_bytep* row_pointers = png_get_rows(PngPtr, InfoPtr);
//
//	// 拷贝!!注意,如果你读取的png没有A通道,就要3位3位的读。还有就是注意字节对其的问题,最简单的就是别用不能被4整除的宽度就行了。读过你实在想用,就要在这里加上相关的对齐处理。
//
//	for (int i = 0; i < m_height; i++)
//	{
//		for (int j = 0; j < (4 * m_width); j += 4)
//		{
//			bgra[pos++] = row_pointers[i][j + 2]; // blue
//			bgra[pos++] = row_pointers[i][j + 1]; // green
//			bgra[pos++] = row_pointers[i][j];   // red
//			bgra[pos++] = row_pointers[i][j + 3]; // alpha
//		}
//	}
//
//	// 好了,你可以用这个数据作任何的事情了。。。把它显示出来或者打印出来都行。
//
//	png_destroy_read_struct(&png_ptr, &info_ptr, 0);
//
//	fclose(file);
//
//	return;
//
//}
//
//
//int main(int c, char** v) {
//
//	png_structp png_ptr;
//	png_infop info_ptr;
//	int bit_depth;
//	FILE *fp;
//
//	printf("lpng[%s], zlib[%s]\n", PNG_LIBPNG_VER_STRING, ZLIB_VERSION);
//
//	if ((fp = fopen("1.png", "rb")) == NULL) {
//		return EXIT_FAILURE;
//	}
//	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
//	if (png_ptr == NULL)
//	{
//		fclose(fp);
//		return EXIT_FAILURE;
//	}
//	info_ptr = png_create_info_struct(png_ptr);
//	if (info_ptr == NULL)
//	{
//		fclose(fp);
//		png_destroy_read_struct(&png_ptr, NULL, NULL);
//		return EXIT_FAILURE;
//	}
//	if (setjmp(png_jmpbuf(png_ptr))) {
//		/* Free all of the memory associated with the png_ptr and info_ptr */
//		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
//		fclose(fp);
//		/* If we get here, we had a problem reading the file */
//		return EXIT_FAILURE;
//	}
//	/* Set up the input control if you are using standard C streams */
//	png_init_io(png_ptr, fp);
//	//读取png文件
//	png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND, 0);
//	//获取png图片相关信息
//	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
//	printf("width[%d], height[%d], bit_depth[%d], color_type[%d]\n",
//		width, height, bit_depth, color_type);
//
//	//获得所有png数据
//	png_bytep* row_pointers = png_get_rows(png_ptr, info_ptr);
//	//计算buffer大小
//	unsigned int bufSize = 0;
//	if (color_type == PNG_COLOR_TYPE_RGB) {
//		bufSize = getRowBytes(width) * height;
//	}
//	else if (color_type == PNG_COLOR_TYPE_RGBA) {
//		bufSize = width * height * 4;
//	}
//	else{
//		return EXIT_FAILURE;
//	}
//	//申请堆空间
//	buffer = (unsigned char*)malloc(bufSize);
//	int i;
//	for (i = 0; i < height; i++) {
//		//拷贝每行的数据到buffer,
//		//opengl原点在下方,拷贝时要倒置一下
//		if (color_type == PNG_COLOR_TYPE_RGB){
//			memcpy(buffer + getRowBytes(width) * i, row_pointers[height - i - 1], width * 3);
//		}
//		else if (color_type == PNG_COLOR_TYPE_RGBA){
//			memcpy(buffer + i * width * 4, row_pointers[height - i - 1], width * 4);
//		}
//	}
//	png_destroy_read_struct(&png_ptr, &info_ptr, 0);
//	fclose(fp);
//	return 0;
//}

//int window_width = 600;
//int window_height = 600;
//
//int pic_width;
//int pic_height;
//int size;
//
//GLuint texName;
//unsigned char *content;
//
//void init()
//{
//	//glewInit();
//
//	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//	glGenTextures(1, &texName);
//	glBindTexture(GL_TEXTURE_2D, texName);
//
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pic_width, pic_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, content);
//}
//
//void display_func()
//{
//	glMatrixMode(GL_PROJECTION);
//	glLoadIdentity();
//	gluOrtho2D(0.0, 1.0f, 0.0, 1.0f);
//
//	glViewport(0, 0, window_width, window_height);
//	glClearColor(1.0f, 1.0f, 1.0f, 1.0);
//	glClear(GL_COLOR_BUFFER_BIT);
//
//	glEnable(GL_TEXTURE_2D);
//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//	glBindTexture(GL_TEXTURE_2D, texName);
//	//glTranslated(0.2f, 0.0f, 0.2f);
//	glRotated(30.0f, 0.2f, 0.0f, 0.0f);
//
//	glBegin(GL_QUADS);
//	glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
//	glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 0.0f);
//	glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f);
//	glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 1.0f);
//	
//	glEnd();
//	glutSwapBuffers();
//}
//
//void reshape_func(int width, int height)
//{
//	window_width = width;
//	window_height = height;
//	glutReshapeWindow(window_width, window_height);
//}
//
//int main(int argc, char **argv)
//{
//	FILE* file = fopen("1.png", "rb");
//	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
//	png_infop info_ptr = png_create_info_struct(png_ptr);
//	setjmp(png_jmpbuf(png_ptr));
//	png_init_io(png_ptr, file);
//	png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND, 0);
//
//	pic_width = png_get_image_width(png_ptr, info_ptr);
//	pic_height = png_get_image_height(png_ptr, info_ptr);
//	int color_type = png_get_color_type(png_ptr, info_ptr);
//
//	size = pic_height * pic_width * 4;
//	int pos = 0;
//	content = (unsigned char *)malloc(sizeof(unsigned char)*size);
//
//	png_bytep* row_pointers = png_get_rows(png_ptr, info_ptr);
//
//	for (int i = 0; i < pic_height; i++)
//	{
//		for (int j = 0; j < pic_width; j++)
//		{
//			content[i*pic_width * 4 + j * 4 + 0] = row_pointers[i][j * 4 + 0];
//			content[i*pic_width * 4 + j * 4 + 1] = row_pointers[i][j * 4 + 1];
//			content[i*pic_width * 4 + j * 4 + 2] = row_pointers[i][j * 4 + 2];
//			content[i*pic_width * 4 + j * 4 + 3] = row_pointers[i][j * 4 + 3];
//		}
//	}
//
//	png_destroy_read_struct(&png_ptr, &info_ptr, 0);
//	fclose(file);
//
//	window_width = pic_width;
//	window_height = pic_height;
//
//	glutInit(&argc, argv);
//	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
//	glutInitWindowSize(window_width, window_height);
//	glutCreateWindow("Picture");
//
//	init();
//
//	glutDisplayFunc(display_func);
//	glutReshapeFunc(reshape_func);
//
//	glutMainLoop();
//
//	free(content);
//
//	return 0;
//}

// OGLTtest.cpp : 定义控制台应用程序的入口点。
//


#define GLEW_STATIC


class gl_texture_t{
public:
	GLsizei width;
	GLsizei height;
	GLenum format;
	GLint internalFormat;
	GLuint id;
	GLubyte *texels;
};
/* Texture id for the demo */
gl_texture_t *ReadPNGFromFile(const char *filename);
GLuint loadPNGTexture(const char *filename);
void GetPNGtextureInfo(int color_type, gl_texture_t *texinfo);

using namespace std;

unsigned int LoadTex(string Image)
{
	unsigned int Texture = 0;

	FILE* img = NULL;
	fopen_s(&img, Image.c_str(), "rb");

	unsigned long bWidth = 0;
	unsigned long bHeight = 0;
	unsigned long  size = 0;

	fseek(img, 18, SEEK_SET);
	fread(&bWidth, 4, 1, img);
	fread(&bHeight, 4, 1, img);
	fseek(img, 0, SEEK_END);
	size = ftell(img) - 54;

	unsigned char *data = (unsigned char*)malloc(size);
	fseek(img, 54, SEEK_SET);    // image data
	fread(data, size, 1, img);

	fclose(img);

	unsigned int t2 = 0;
	glGenTextures(1, &Texture);
	glGenTextures(1, &t2);
	glBindTexture(GL_TEXTURE_2D, Texture);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, bWidth, bHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, data);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	if (data)
		free(data);

	return Texture;
}

int main(void)
{

	GLFWwindow* window;

	/* Initialize the library */
	if (!glfwInit())
		return -1;

	/* Create a windowed mode window and its OpenGL context */
	window = glfwCreateWindow(480, 640, "Hello World", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		return -1;
	}


	/* Make the window's context current */
	glfwMakeContextCurrent(window);

	//unsigned int img = LoadTex("d:\\b0.bmp");
	unsigned int img = loadPNGTexture("1.png");
	unsigned int mask_img = LoadTex("1.bmp");
	//unsigned int tid = ATLLoadTexture(L"d:\\b0.png");
	/* Loop until the user closes the window */
	int a = 10;
	while (!glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
		glClearColor(0.0, 0.8, 0.0, 0.5);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		//glTranslated(0.2,0.2,0);
		//glRotated(a, 0.2, 0.2, 0.2);

		//a += 10;

		glEnable(GL_STENCIL_TEST);
		glDepthMask(GL_FALSE);

		//根据掩码图设置模板缓冲区的值
		glStencilFunc(GL_NEVER, 1, 1);
		glStencilOp(GL_REPLACE , GL_KEEP, GL_KEEP);

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, mask_img);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
		glEnd();

		glStencilFunc(GL_EQUAL, 1, 0xff);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

		

		//glEnable(GL_ALPHA_TEST);//非必须
		//glAlphaFunc(GL_GREATER, 0.1);

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, img);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(.5f, -.5f, 1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, 1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 1.0f);
		glEnd();


		/* Swap front and back buffers */
		glfwSwapBuffers(window);

		/* Poll for and process events */
		glfwPollEvents();
		Sleep(200);
	}

	glfwTerminate();
	return 0;
}

//以下函数引用别人的。
gl_texture_t * ReadPNGFromFile(const char *filename)
{
	gl_texture_t *texinfo;
	png_byte magic[8];
	png_structp png_ptr;
	png_infop info_ptr;
	int bit_depth, color_type;
	FILE *fp = NULL;
	png_bytep *row_pointers = NULL;
	png_uint_32 w, h;
	int i;
	/* Open image file */
	fopen_s(&fp, filename, "rb");
	if (!fp)
	{
		fprintf(stderr, "error: couldn't open \"%s\"!\n", filename);
		return NULL;
	}
	/* Read magic number */
	fread(magic, 1, sizeof(magic), fp);
	/* Check for valid magic number */
	if (!png_check_sig(magic, sizeof(magic)))
	{
		fprintf(stderr, "error: \"%s\" is not a valid PNG image!\n", filename);
		fclose(fp);
		return NULL;
	}
	/* Create a png read struct */
	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (!png_ptr)
	{
		fclose(fp);
		return NULL;
	}
	/* Create a png info struct */
	info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr)
	{
		fclose(fp);
		png_destroy_read_struct(&png_ptr, NULL, NULL);
		return NULL;
	}
	/* Create our OpenGL texture object */
	texinfo = (gl_texture_t *)malloc(sizeof(gl_texture_t));
	/* Initialize the setjmp for returning properly after a libpng error occured */
	if (setjmp(png_jmpbuf(png_ptr)))
	{
		fclose(fp);
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
		if (row_pointers) free(row_pointers);
		if (texinfo) {
			if (texinfo->texels)
				free(texinfo->texels);
			free(texinfo);
		}
		return NULL;
	}
	/* Setup libpng for using standard C fread() function with our FILE pointer */
	png_init_io(png_ptr, fp);
	/* Tell libpng that we have already read the magic number */
	png_set_sig_bytes(png_ptr, sizeof(magic));
	/* Read png info */
	png_read_info(png_ptr, info_ptr);
	/* Get some usefull information from header */
	bit_depth = png_get_bit_depth(png_ptr, info_ptr);
	color_type = png_get_color_type(png_ptr, info_ptr);
	/* Convert index color images to RGB images */
	if (color_type == PNG_COLOR_TYPE_PALETTE)
		png_set_palette_to_rgb(png_ptr);
	/* Convert 1-2-4 bits grayscale images to 8 bits grayscale. */
	if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
		png_set_expand_gray_1_2_4_to_8(png_ptr);

	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
		png_set_tRNS_to_alpha(png_ptr);
	if (bit_depth == 16) png_set_strip_16(png_ptr);
	else if (bit_depth < 8) png_set_packing(png_ptr);
	/* Update info structure to apply transformations */
	png_read_update_info(png_ptr, info_ptr);
	/* Retrieve updated information */
	png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type, NULL, NULL, NULL);
	texinfo->width = w;
	texinfo->height = h;
	/* Get image format and components per pixel */
	GetPNGtextureInfo(color_type, texinfo);
	/* We can now allocate memory for storing pixel data */
	texinfo->texels = (GLubyte *)malloc(sizeof(GLubyte) * texinfo->width * texinfo->height * texinfo->internalFormat);
	/* Setup a pointer array. Each one points at the begening of a row. */
	row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * texinfo->height);
	for (i = 0; i < texinfo->height; ++i)
	{
		row_pointers[i] = (png_bytep)(texinfo->texels + ((texinfo->height - (i + 1)) * texinfo->width * texinfo->internalFormat));
	}
	/* Read pixel data using row pointers */
	png_read_image(png_ptr, row_pointers);
	/* Finish decompression and release memory */
	png_read_end(png_ptr, NULL);
	png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
	/* We don't need row pointers anymore */
	free(row_pointers);
	fclose(fp);
	return texinfo;
}
GLuint loadPNGTexture(const char *filename)
{
	gl_texture_t *png_tex = NULL;
	GLuint tex_id = 0;
	GLint alignment;
	png_tex = ReadPNGFromFile(filename);
	if (png_tex && png_tex->texels)
	{
		/* Generate texture */
		glGenTextures(1, &png_tex->id);
		glBindTexture(GL_TEXTURE_2D, png_tex->id);
		/* Setup some parameters for texture filters and mipmapping */
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glTexImage2D(GL_TEXTURE_2D, 0, png_tex->internalFormat, png_tex->width, png_tex->height, 0, png_tex->format, GL_UNSIGNED_BYTE, png_tex->texels);
		glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
		tex_id = png_tex->id;
		/* OpenGL has its own copy of texture data */
		free(png_tex->texels);
		free(png_tex);
	}
	return tex_id;
}

void GetPNGtextureInfo(int color_type, gl_texture_t *texinfo)
{
	switch (color_type)
	{
	case PNG_COLOR_TYPE_GRAY:
		texinfo->format = GL_LUMINANCE;
		texinfo->internalFormat = 1;
		break;

	case PNG_COLOR_TYPE_GRAY_ALPHA:
		texinfo->format = GL_LUMINANCE_ALPHA;
		texinfo->internalFormat = 2;
		break;

	case PNG_COLOR_TYPE_RGB:
		texinfo->format = GL_RGB;
		texinfo->internalFormat = 3;
		break;

	case PNG_COLOR_TYPE_RGB_ALPHA:
		texinfo->format = GL_RGBA;
		texinfo->internalFormat = 4;
		break;

	default:
		/* Badness */
		break;
	}
}

 


Taily老段的微信公众号,欢迎交流学习

https://blog.csdn.net/taily_duan/article/details/81214815


 

 

 

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值