OpenGL函数学习
1.glBitmap
例子 画出三个F。各字符间距不同。
#include <GL/glut.h>
#include <stdlib.h>
GLubyte rasters[24] = {
0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0xc0, 0xff, 0xc0};
void init(void)
{
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glClearColor (0.0, 0.0, 0.0, 0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glRasterPos2i (20, 20);
//void glBitmap( GLsizei width, //位图的宽度
//GLsizei height, //位图的高度
//GLfloat xorig, //定义位图原点
//GLfloat yorig, //定义位图原点
//GLfloat xmove, //表示位图被光栅化之后的光栅位置的x y增加值
//GLfloat ymove,
//const GLubyte * bitmap);
//11.0 光栅后 光栅位置在x向移动10个像素
glBitmap (10, 12, 0.0, 0.0, 10.0, 0.0, rasters);
//光栅后 光栅位置在x向移动20个像素
glBitmap (10, 12, 0.0, 0.0, 20.0, 0.0, rasters);
//11.0 光栅后 光栅位置在x向移动40个像素
glBitmap (10, 12, 0.0, 0.0, 40.0, 0.0, rasters);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, w, 0, h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
}
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100, 100);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
#include <stdlib.h>
GLubyte rasters[24] = {
0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0xc0, 0xff, 0xc0};
void init(void)
{
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glClearColor (0.0, 0.0, 0.0, 0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glRasterPos2i (20, 20);
//void glBitmap( GLsizei width, //位图的宽度
//GLsizei height, //位图的高度
//GLfloat xorig, //定义位图原点
//GLfloat yorig, //定义位图原点
//GLfloat xmove, //表示位图被光栅化之后的光栅位置的x y增加值
//GLfloat ymove,
//const GLubyte * bitmap);
//11.0 光栅后 光栅位置在x向移动10个像素
glBitmap (10, 12, 0.0, 0.0, 10.0, 0.0, rasters);
//光栅后 光栅位置在x向移动20个像素
glBitmap (10, 12, 0.0, 0.0, 20.0, 0.0, rasters);
//11.0 光栅后 光栅位置在x向移动40个像素
glBitmap (10, 12, 0.0, 0.0, 40.0, 0.0, rasters);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, w, 0, h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
}
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100, 100);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
如图所示
浙公网安备 33010602011771号