OpenGL学习笔记(三)画三角形

1.画一个背景是紫色,有一个黄色三角形的窗口
 

#include "Dependencies\glew\glew.h"
#include "Dependencies\freeglut\freeglut.h"

void display(void)
{
    // clear all pixels  
    glClear(GL_COLOR_BUFFER_BIT);

    // draw yellow polygon (rectangle) with corners at
    glColor3f(1.0, 1.0, 0.0);
    glBegin(GL_TRIANGLES);
    //绘制开始前必须调用glBegin以通知绘制图形的类型,比如还可以绘制点,线等。
   
    glVertex3f(0.2f, 0.8f, 0.0f);
  
    glVertex3f(0.2f, 0.2f, 0.0f);
 
    glVertex3f(0.8f, 0.2f, 0.0f);
    glEnd();                              //结束之后则要调用glEnd函数

    glFlush();
}

void init(void)
{
    // select clearing color: purple
    glClearColor(0.6, 0.3, 0.6, 0.0);

    // initialize viewing values
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("2018计算机图形");
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

2.画一个smooth着色的矩形

#include "Dependencies\glew\glew.h"
#include "Dependencies\freeglut\freeglut.h"

void display(void)
{
	// clear all pixels  
	glClear(GL_COLOR_BUFFER_BIT);

	// draw yellow polygon (rectangle) with corners at
	//glColor3f(1.0, 1.0, 0.0);
	glBegin(GL_POLYGON);
	//绘制开始前必须调用glBegin以通知绘制图形的类型,比如还可以绘制点,线等。
	glShadeModel(GL_SMOOTH);
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.2f, 0.8f, 0.0f);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(0.2f, 0.2f, 0.0f);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(0.8f, 0.2f, 0.0f);
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.8f, 0.8f, 0.0f);
	glEnd();                              //结束之后则要调用glEnd函数

	glFlush();
}

void init(void)
{
	// select clearing color: purple
	glClearColor(0.0, 0.0, 0.0, 0.0);

	// initialize viewing values
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("2018计算机图形");
	init();
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值