opengl位图

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

#include "stdafx.h"
#include <gl/glew.h>
#include <gl/glut.h>

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

unsigned char raster[] =
{
	0xc0,0x00,0xc0,0x00,
	0xc0,0xc0,0xc0,0x00,
	0xc0,0x00,0xff,0x00,
	0xff,0x00,0xc0,0x00,
	0xc0,0x00,0xc0,0x00,
	0xff,0xc0,0x0ff,0xc0,
};


GLubyte haoBitmap[32]=
{
	0x00, 0x00,
	0x00, 0x00,
	0x00, 0xe0,
	0xe1, 0xf0,
	0x3e, 0x18,
	0x0c, 0x18,
	0x1c, 0x18,
	0x34, 0x19,
	0x25, 0xff,
	0xfe, 0x10,
	0x30, 0x30,
	0x18, 0x8e,
	0x0c, 0xfe,
	0x04, 0x00,
	0x00, 0x00,
	0x00, 0x00
};

void init()
{
	glClearColor(0,0,0,0);
	glPixelStoref(GL_UNPACK_ALIGNMENT, 1);
}

void reshape(int w, int h)
{
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if (w > h)
	{
		float factor = (float)w/h;
		gluOrtho2D(-10*factor, 10*factor, -10, 10);
	}
	else
	{
		float factor = (float)w/h;
		gluOrtho2D(-10, 10, -10*factor, 10*factor);
	}
	glMatrixMode(GL_MODELVIEW);
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();

	glColor3f(1.0, 0, 0);
	glRasterPos2f(-5,0); //大地坐标
	glBitmap(16, 16, 0, 0, 0, 0, haoBitmap); //像素偏移

	glColor3f(1,1,1);
	glRasterPos2f(0,0);

	glBitmap(10, 12, 0, 0, 11, 0, raster);
	glBitmap(10, 12, 0, 0, 11, 0, raster);

	glutSwapBuffers();
}

int _tmain(int argc, _TCHAR* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
	glutInitWindowPosition(300, 300);
	glutInitWindowSize(600,600);
	glutCreateWindow("Bitmap");

	glewInit();
	init();
	glutReshapeFunc(reshape);
	glutDisplayFunc(display);
	glutMainLoop();

	return 0;
}
opengl位图_第1张图片

你可能感兴趣的:(OpenGL,位图)