OpenGL 学习笔记(1)初始化窗体
来源:互联网 发布:c语言type buffer 编辑:程序博客网 时间:2024/06/06 09:16
前言
学习OpenGL只是兴趣爱好,因为对图形比较感兴趣.将以OpenGl的红宝书(7)和蓝宝石书(4)为基础,虽然手头有红宝书书,但感觉没蓝宝石书写的好
准备工作
首先要下载一个工具库(GLUT)
http://www.opengl.org/resources/libraries/glut/
只要把相应文件放在system32和lib目录下就可以了
第一个OpenGL程序
#include <GL/glut.h>#include <stdlib.h>void display(void){ /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); glFlush ();}int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); glClearColor (0.0, 0.0, 1.0, 0.0); glutDisplayFunc(display); glutMainLoop(); return 0;}
显示效果是显示一个蓝色背景的一个窗体
窗体管理(Window Management)
Several routines perform tasks necessary for initializing a window:
? glutInit(int *argc, char **argv) initializes GLUT and processes any command
line arguments (for X, this would be options such as -display and
-geometry). glutInit() should be called before any other GLUT routine.
? glutInitDisplayMode(unsigned int mode) specifies whether to use an
RGBA or color-index color model. You can also specify whether you
want a single- or double-buffered window. (If you’re working in colorindex
mode, you’ll want to load certain colors into the color map; use
glutSetColor() to do this.) Finally, you can use this routine to indicate
that you want the window to have an associated depth, stencil,
multisampling, and/or accumulation buffer. For example, if you want
a window with double buffering, the RGBA color model, and a depth
buffer, you might call glutInitDisplayMode(GLUT_DOUBLE |
GLUT_RGBA | GLUT_DEPTH).
? glutInitWindowPosition(int x, int y) specifies the screen location for
the upper-left corner of your window.
? glutInitWindowSize(int width, int height) specifies the size, in pixels,
of your window.
? glutInitContextVersion(int majorVersion, int minorVersion) specifies
which version of OpenGL you want to use. (This is a new addition
available only when using Freeglut, and was introduced with OpenGL
Version 3.0. See “OpenGL Contexts” on page 27 for more details on
OpenGL contexts and versions.)
? glutInitContextFlags(int flags) specifes the type of OpenGL context
you want to use. For normal OpenGL operation, you can omit this call
from your program. However, if you want to use a forward-compatible
OpenGL context, you will need to call this routine. (This is also a new
addition available only in Freeglut, and was introduced with OpenGL
Version 3.0. See “OpenGL Contexts” on page 27 for more details on
the types of OpenGL contexts.)
? int glutCreateWindow(char *string) creates a window with an OpenGL
context. It returns a unique identifier for the new window. Be warned:
until glutMainLoop() is called, the window is not yet displayed.
我们知道低级win32 api初始化一个窗体是比较复杂的,glut库简化了这个过程
回调函数
即win32的消息循环系统,
glutDisplayFunc调用一个函数,该函数会不断的被调用
glutMainLoop用于启动程序,并使程序不断在运行不退出,即进入消息循环
glClearColor 用于清除缓冲区颜色,并重新设置新的颜色
guFlush 刷新OpenGl命令队列,如果不调用此方法,那么重新绘制的图形将无法显示
本节目的在于建立OpenGL环境,并建立一个初始窗体
- OpenGL 学习笔记(1)初始化窗体
- OPENGL学习笔记1
- OpenGL 学习笔记(1)
- Opengl学习笔记1
- opengl 学习笔记1
- opengl学习笔记(1)
- OpenGL学习笔记1
- OpenGL学习笔记1
- opengl学习笔记【1】
- opengl 学习笔记1
- openGL学习笔记 1
- OpenGL学习笔记1:OpenGL概述
- openGL学习 第一步 创建窗体
- OpenGL 学习笔记(1)
- ckeditor 学习笔记【1】初始化
- 学习OpenGL-ES: 1 - 像素、颜色、显存、初始化
- OpenGL实例(1)-创建窗体
- OpenGL ES2学习笔记(1)-- OpenGL Console
- RemoteException occurred in server thread; nested exception is:
- OpenGL 在 VC++中的使用
- 松乐srd05vdc继电器使用
- glNewList,glEndList 用于创建和替换一个显示列表函数原型
- glPushMatrix()和glPopMatrix()以及glLoadIdentity()的理解
- OpenGL 学习笔记(1)初始化窗体
- OpenGL 学习笔记(2)创建第一个图形
- OpenGL 学习笔记(3)绘制几何物体
- OpenGL 学习笔记(4)顶点数组
- OpenGL学习笔记(5)3D基本概念
- OpenGL学习笔记(6)第一个动画
- OpenGL学习笔记(7)多边形绘制
- java中int和Integer什么区别
- OpenGL学习笔记(8)显示列表