【opengl复习】显示框架

在上周昆大神的图形学研究进展,害怕跟不上特地来复习一波opengl

1、显示框架:

/*************************************************************
*Project Name:
*Description: 
*Author: lishichengyan
*Student ID:
*Date:
*Reference:http://www.lighthouse3d.com/tutorials/glut-tutorial/
**************************************************************/
#include<iostream>
using namespace std;
#include<gl/glut.h>

void renderScene(void){
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_TRIANGLES);
	glVertex3f(-0.5f,-0.5f,0.0f);
	glVertex3f(0.5f,0.0f,0.0f);
	glVertex3f(0.0f,0.5f,0.0f);
	glEnd();
	glFlush();
}

/*改变窗口大小时防止图形变形*/
void reshape(int w,int h){
	if(h==0)
		h=1;
	float ratio=1.0f*w/h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glViewport(0,0,w,h);
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0f,0.0f,5.0f,0.0f,0.0f,-1.0f,0.0f,1.0f,0.0f);
}

int main(int argc,char *argv[]){
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(640,480);
	glutCreateWindow("图形学的日常");
	glutDisplayFunc(renderScene);
	glutReshapeFunc(reshape);
	//glutIdleFunc(idle);
	glutMainLoop();
	return 1;
}

2、GLUT_SINGLE和GLUT_DOUBLE

When using GL_SINGLE, you can picture your code drawing directly to the display.

When using GL_DOUBLE, you can picture having two buffers. One of them is always visible, the other one is not. You always render to the buffer that is not currently visible. When you're done rendering the frame, you swap the two buffers, making the one you just rendered visible. The one that was previously visible is now invisible, and you use it for rendering the next frame. So the role of the two buffers is reversed each frame.

(来自StackOverflow:点击打开链接)

3、glutMainLoop干了什么?

glutMainLoop() is a function that loops within itself, processing events and triggering your callback functions when necessary (glutDisplayFunc, etc). After a call to glutMainLoop(), you have no control over the execution of your program besides the callback functions you initialized before the call.

And another thing, the glutDisplayFunc() callback only gets triggered when your app's window receives a refresh event, unless you explicity post a redisplay. If you want your display function to be called repeatedly (i.e. for a game), you need to set your glutIdleFunc to post a redisplay.

(来自gamedev.net:点击打开链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值