cpu_bitmap结构体解析
来源:互联网 发布:万学海文考研 知乎 编辑:程序博客网 时间:2024/06/05 16:03
#ifndef __CPU_BITMAP_H__
#define __CPU_BITMAP_H__
#include "gl_helper.h"
struct CPUBitmap {
unsigned char *pixels;
int x, y;
void *dataBlock;
void (*bitmapExit)(void*);
//CPUBitmap结构体的构造函数
CPUBitmap( int width, int height, void *d = NULL ) {
pixels = new unsigned char[width * height * 4];//像素点申请
x = width;//图像宽度
y = height;//图像长度
dataBlock = d;//数组块声明(cpu_aini中使用)
}
//CPUBitmap结构体的析构函数
~CPUBitmap() {
delete [] pixels;
}
//获取其像素所在的指针
unsigned char* get_ptr( void ) const { return pixels; }
//获取其像素的个数
long image_size( void ) const { return x * y * 4; }
//显示并退出
//该函数的参数为函数指针。函数指针声明: void(*e)(void*),默认为NULL
void display_and_exit( void(*e)(void*) = NULL ) {
CPUBitmap** bitmap = get_bitmap_ptr();
*bitmap = this;
bitmapExit = e;
// a bug in the Windows GLUT implementation prevents us from
// passing zero arguments to glutInit()
int c=1;
char* dummy = "";
glutInit( &c, &dummy );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGBA );
glutInitWindowSize( x, y );
glutCreateWindow( "bitmap" );
glutKeyboardFunc(Key);
glutDisplayFunc(Draw);
glutMainLoop();
}
//静态函数,用于glut的回调,其返回g指向Bitmap指针的指针
// static method used for glut callbacks
static CPUBitmap** get_bitmap_ptr( void ) {
static CPUBitmap *gBitmap;
return &gBitmap;
}
//静态函数,用于glut的回调,其返回g指向Bitmap指针的指针
// static method used for glut callbacks
static void Key(unsigned char key, int x, int y) {
switch (key) {
case 27:
CPUBitmap* bitmap = *(get_bitmap_ptr());
if (bitmap->dataBlock != NULL && bitmap->bitmapExit != NULL)
bitmap->bitmapExit( bitmap->dataBlock );
exit(0);
}
}
//静态函数,用于glut的回调,其返回g指向Bitmap指针的指针
// static method used for glut callbacks
static void Draw( void ) {
CPUBitmap* bitmap = *(get_bitmap_ptr());
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glClear( GL_COLOR_BUFFER_BIT );
glDrawPixels( bitmap->x, bitmap->y, GL_RGBA, GL_UNSIGNED_BYTE, bitmap->pixels );
glFlush();
}
};
#endif // __CPU_BITMAP_H__
0 0
- cpu_bitmap结构体解析
- CUDA by Example 4.2.2 一个有趣的例子之 CPU_bitmap.h解析
- AVI结构解析 结构体
- FIle_Operation结构体解析
- 网络地址结构体解析
- x264_t 结构体解析
- DEFUN结构体解析
- cpu_anim结构体解析
- 解析 virDomainDef 结构体
- struct net_device结构体解析
- linux i2c_driver 结构体解析
- IplImage结构体数据解析
- AVFormatContext结构体源码解析
- struct stat结构体解析
- 结构体struct 知识解析
- 结构体指针示例解析
- 空结构体struct{}解析
- 解析C语言结构体
- no jlink device found
- AngularJs Controllers
- 十分钟搞定pandas
- 安卓打开File Explorer里面不显示内容
- JavaScript的function和function()的区别
- cpu_bitmap结构体解析
- Android设计模式应用--状态模式
- Android中的Spinner控件)
- Unity3d Shader UV移动
- 12. Integer to Roman
- lintcode:Unique Binary Search Trees II
- cf19B. Checkout Assistant 【01 背包】
- android的消息机制
- Hive与HBase的区别