给出一个OpenGL扩展应用的实例
2008-09-15 17:22
639 查看
// opngl_kuozhan.cpp : Defines the entry point for the console application.
//其中,画红线的部分是要注意的。
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <GL/glew.h>//顺序要正确。
#include <GL/glut.h>
using namespace std ;
void init(void)
{
glClearColor(1.0, 1.0, 0.0, 0.0) ;
glBlendFunc(GL_ONE, GL_ONE) ;
glEnable(GL_BLEND) ;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT) ;
glColor3f(0.0, 0.0, 1.0) ;
glRectf(-0.5, -0.5, 0.5, 0.5) ;
glFlush() ;
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h) ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
if(w<=h)
glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0) ;
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'a':
case 'A':
//Note: glBlendEquation is a subset of GL_ARB_imaging, please call glGetString
//first to confirm whether your video card support this extension.
glBlendEquation(GL_FUNC_ADD) ;
break ;
case 's':
case 'S':
glBlendEquation(GL_FUNC_SUBTRACT) ;
break ;
case 'r':
case 'R':
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT) ;
case 'm':
case 'M':
glBlendEquation(GL_MIN) ;
break ;
case 'x':
case 'X':
glBlendEquation(GL_MAX) ;
break ;
case 27:
exit(0) ;
break ;
}
glutPostRedisplay() ;
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv) ;
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) ;
glutInitWindowSize(200, 200) ;
glutCreateWindow("Blend") ;
GLenum err = glewInit();//初始化glew库
if (GLEW_OK != err)
{
MessageBoxA(NULL, "error", "My Window", 1) ;
}
//if the return value contains "GL_ARB_imaging " then you can use glBlendEquation
const GLubyte *str = glGetString(GL_EXTENSIONS) ;
cout << str << endl ;//输出硬件所支持的所有扩展本例中主要是"GL_ARB_imaging "
init() ;
glutReshapeFunc(reshape) ;
glutKeyboardFunc(keyboard) ;
glutDisplayFunc(display) ;
glutMainLoop() ;
return 0 ;
}
实例图片在博客相册部分
//其中,画红线的部分是要注意的。
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <GL/glew.h>//顺序要正确。
#include <GL/glut.h>
using namespace std ;
void init(void)
{
glClearColor(1.0, 1.0, 0.0, 0.0) ;
glBlendFunc(GL_ONE, GL_ONE) ;
glEnable(GL_BLEND) ;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT) ;
glColor3f(0.0, 0.0, 1.0) ;
glRectf(-0.5, -0.5, 0.5, 0.5) ;
glFlush() ;
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h) ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
if(w<=h)
glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0) ;
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'a':
case 'A':
//Note: glBlendEquation is a subset of GL_ARB_imaging, please call glGetString
//first to confirm whether your video card support this extension.
glBlendEquation(GL_FUNC_ADD) ;
break ;
case 's':
case 'S':
glBlendEquation(GL_FUNC_SUBTRACT) ;
break ;
case 'r':
case 'R':
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT) ;
case 'm':
case 'M':
glBlendEquation(GL_MIN) ;
break ;
case 'x':
case 'X':
glBlendEquation(GL_MAX) ;
break ;
case 27:
exit(0) ;
break ;
}
glutPostRedisplay() ;
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv) ;
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) ;
glutInitWindowSize(200, 200) ;
glutCreateWindow("Blend") ;
GLenum err = glewInit();//初始化glew库
if (GLEW_OK != err)
{
MessageBoxA(NULL, "error", "My Window", 1) ;
}
//if the return value contains "GL_ARB_imaging " then you can use glBlendEquation
const GLubyte *str = glGetString(GL_EXTENSIONS) ;
cout << str << endl ;//输出硬件所支持的所有扩展本例中主要是"GL_ARB_imaging "
init() ;
glutReshapeFunc(reshape) ;
glutKeyboardFunc(keyboard) ;
glutDisplayFunc(display) ;
glutMainLoop() ;
return 0 ;
}
实例图片在博客相册部分
相关文章推荐
- 实例解析:设计一个完全可扩展的应用
- 实例解析:设计一个完全可扩展的应用
- hybrid的一个实例应用分析
- set,bitset 的一个应用实例——数据结构和比较算法
- C语言入门(17)——C语言数组应用的一个实例
- 一个小应用的dbcp和c3p0配置实例
- Note_Cotes公式的一个实例应用
- 最简单直接继承、扩展Object,或者克隆一个Object到能创建多个互不干扰实例的方法
- 一个tomcat部署多个应用实例总结
- 单片机扩展触摸屏人机接口的应用实例
- 使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之一
- php扩展类PECL扩展实例ZIP应用出错解决
- samba服务器在企业中的一个应用实例 推荐
- 一个简单的OpenGL实例
- 一个awk应用实例
- 实例:把一个/oldboy目录及其子目录所有的扩展名.sh结尾的文件中包含oldboy的字符全部替换为beautiful
- 漫谈C指针:一个指针应用实例
- tomcat配置及使用(环境变量设置及测试,一个简单的web应用实例)
- Java与数据库的结合,应用实例。以学生表、选课表为例。可以自己扩展功能。
- Oracle data integrator 11g安装配置和一个实例应用指南pdf