計算機圖形學-實驗1-掌握開發環境配置方法和基本圖元繪製函數

實驗一:(2學時)


一、 實驗目的:

掌握開發環境配置方法和基本圖元繪製函數


二、 實驗內容:

1、熟悉開發環境

2、掌握點、線等基本圖元繪製函數


三、 開發工具簡介、實現效果及步驟

1、開發工具簡介

Microsoft Visual Studio 是微軟公司的一款集成開發環境IDE),開發平臺爲Windows操作系統

2、實現效果、步驟(或流程)

1)配置環境成功:


(2) 直線源碼運行:



四、 創新設計和實現方法

a) 實現直線顏色修改:


b) 實現直線粗細修改:


c) 實現直線改線段

d) 實現顏色漸變

e) 畫一個點



源碼如下:

#include "stdafx.h"
#include <GL/glut.h>      
void init(void)
{
	glClearColor(1.0, 1.0, 1.0, 0.0);  // Set display-window color to white.
	glMatrixMode(GL_PROJECTION);       // Set projection parameters.
	gluOrtho2D(0.0, 200.0, 0.0, 150.0);  //設置窗口座標範圍
}
void lineSegment(void)
{
	glClear(GL_COLOR_BUFFER_BIT);  // Clear display window.

	glLineWidth(10);//粗細
	glLineStipple(1, 0xFFF2);//線段
	glEnable(GL_LINE_STIPPLE);//開啓變化
	glColor3f(0, 0.4, 0.2);      //顏色
	glShadeModel(GL_SMOOTH);

	glBegin(GL_LINES);
	glColor3f(0.0, 0.0, 1.0);//藍
	glVertex2i(180, 15);       // Specify line-segment geometry.
	glColor3f(1.0, 0.0, 0.0);//紅
	glVertex2i(10, 145);
	glEnd();
  

	glPointSize(10);
	glBegin(GL_POINTS);
	glColor3f(0, 0, 1);
	glVertex2i(50, 10);
	glEnd();
	glFlush();   
	// Process all OpenGL routines as quickly as possible.
}
void main(int argc, char** argv)
{

	glutInit(&argc, argv);                         // Initialize GLUT.
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);   // Set display mode.
	glutInitWindowPosition(50, 100);   // Set top-left display-window position.
	glutInitWindowSize(400, 300);      // 設置窗口在顯示器上的大小
	glutCreateWindow("TheFirstProgram"); // Create display window.

	init();                            // Execute initialization procedure.
	glutDisplayFunc(lineSegment);       // Send graphics to display window.
	glutMainLoop();                    // Display everything and wait.
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章