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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值