#include <iostream> #include <gl/glew.h> #include <gl/glut.h> using namespace std; #pragma comment(lib,"opengl32.lib") #pragma comment(lib,"glut32.lib") #pragma comment(lib,"glu32.lib") #pragma comment(lib,"glew32.lib") void init() { GLenum err=glewInit(); if(err!=GLEW_OK){ cout<<"glew初始化错误"<<endl; return; } glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_ONE); } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glRectf(-0.3,-0.3,0.1,0.1); glColor3f(0.0,1.0,1.0); glRectf(0.0,0.0,0.4,0.4); glFlush(); } void keyboard(unsigned char key,int x,int y) { switch(key) { case 'a': case 'A': glBlendEquation(GL_FUNC_ADD); break; case 's': case 'S': glBlendEquation(GL_FUNC_SUBTRACT); break; case 'e': case 'E':
exit(0);
} glutPostRedisplay(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
其实这么简单的程序也还是遇到问题的。。主要是关于opengl扩展的问题,其实在windows提供给我们的只有openg1.1的功能,opengl1.1以上的功能我们并不能用。具体体现在这个程序中的glBlendEquation函数,具体解决方案请看下一篇。。。。