hello world by OpenGL

来源:互联网 发布:全民公敌里卫星 知乎 编辑:程序博客网 时间:2024/05/23 11:59

博客的密码忘了,有点囧。。

开始学opengl,之前看书说opengl是状态机,不明白是什么回事,昨天看书突然一下子就明白了,opengl的函数只是维护各种绘图的状态,不关心具体的硬件的实现,硬件的实现应该是有硬件商实现,说白了就是opengl提供了一个接口标准。

hello world by OpenGL


#include <Windows.h>#include <iostream>#include<gl/GL.h>#include <gl/GLU.h>#include <gl/glut.h>void display(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0, 1.0, 1.0);glBegin(GL_POLYGON);glVertex3f(0.25, 0.25, 0);glVertex3f(0.75, 0.25, 0);glVertex3f(0.75, 0.75, 0);glVertex3f(0.25, 0.75, 0);glEnd();glFlush();}void init(void){glClearColor(0.0, 0.0, 0.0, 0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0, 1.0, 0, 1.0, -1.0, 1.0);}int main(int argc, char ** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowSize(250, 250);glutInitWindowPosition(100, 100);glutCreateWindow("Hello world");init();glutDisplayFunc(display);glutMainLoop();return 0;}


0 0