国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

OpenGL 學習筆記3_1(繪制點相關)

2019-11-11 04:43:55
字體:
來源:轉載
供稿:網友

藍寶書 第三章

畫點 Point

1)單個點

glVertex3f(50.0f,50.0f,0.0f)  3D圖像的點

glVertex2f(50.0f,50.0f)         2D圖像的點

2)多個點

glBegin(GL_POINTS)

……

glEnd();

相關代碼見例3.2

3)設置點大小

void glPointSize(GLfloatsize);設置點的大小

GLfloat sizes[2]; // 存放點大小的范圍

GLfloat step; // 存放每次改變點大小的最小增量

glGetFloatv(GL_POINT_SIZE_RANGE,sizes);

glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);

相關代碼見例3.3

例3.1 窗口改變響應函數--3D版

void ChangeSize(GLsizei w, GLsizei h){	GLfloat nRange = 100.0f;	// PRevent a divide by zero	if (h == 0)		h = 1;	// Set Viewport to window dimensions	glViewport(0, 0, w, h);	// Reset projection matrix stack	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Establish clipping volume (left, right, bottom, top, near, far)		if (w <= h)		glOrtho(-nRange, nRange, -nRange*h / w, nRange*h / w, -nRange, nRange);	else		glOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);	// Reset Model view matrix stack	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}例3.2   顯示多個點

#include <windows.h>#include <math.h>#include <GL/GL.h>#include <GL/GLU.h>#include <GL/glut.h>// Define a constant for the value of PI#define GL_PI 3.1415f// This function does any needed initialization on the renderingvoid RenderScene(void){	GLfloat x, y, z, angle; // Storage for coordinates and angles	// Clear the window with current clearing color	glClear(GL_COLOR_BUFFER_BIT);	// Save matrix state and do the rotation	glPushMatrix();	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);//書中的xRot代表x軸偏移的角度,此處改為x軸偏移30度	glRotatef(30.0f, 0.0f, 1.0f, 0.0f);//書中的yRot代表y軸偏移的角度,此處改為y軸偏移30度	// Call only once for all remaining points	glBegin(GL_POINTS);	z = -50.0f;	for (angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f)	{		x = 50.0f*sin(angle);//sin輸入為弧度		y = 50.0f*cos(angle);		// Specify the point and move the Z value up a little		glVertex3f(x, y, z);		z += 0.5f;	}	// Done drawing points	glEnd();	// Restore transformations	glPopMatrix();	// Flush drawing commands	glutSwapBuffers();}void SetupRC(){	// Black background	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);	// Set drawing color to green	glColor3f(0.0f, 1.0f, 0.0f);}void ChangeSize(GLsizei w, GLsizei h){	GLfloat nRange = 100.0f;	// Prevent a divide by zero	if (h == 0)		h = 1;	// Set Viewport to window dimensions	glViewport(0, 0, w, h);	// Reset projection matrix stack	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Establish clipping volume (left, right, bottom, top, near, far)		if (w <= h)		glOrtho(-nRange, nRange, -nRange*h / w, nRange*h / w, -nRange, nRange);	else		glOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);	// Reset Model view matrix stack	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}int main(int argc, char* argv[]){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);	glutInitWindowSize(800, 600);	glutCreateWindow("Bounce");	glutDisplayFunc(RenderScene);//顯示回調函數	glutReshapeFunc(ChangeSize);//窗口大小變形回調函數	SetupRC();	glutMainLoop();	return 0;}例3.3 點大小的改變

#include <windows.h>#include <math.h>#include <GL/GL.h>#include <GL/GLU.h>#include <GL/glut.h>// Define a constant for the value of PI#define GL_PI 3.1415f// This function does any needed initialization on the renderingvoid RenderScene(void){	GLfloat x, y, z, angle; // Storage for coordinates and angles	GLfloat sizes[2]; // Store supported point size range	GLfloat step; // Store supported point size increments	GLfloat curSize; // Store current point size		// Clear the window with current clearing color	glClear(GL_COLOR_BUFFER_BIT);	// Save matrix state and do the rotation	glPushMatrix();	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);//書中的xRot代表x軸偏移的角度	glRotatef(30.0f, 0.0f, 1.0f, 0.0f);//書中的yRot代表y軸偏移的角度	// Get supported point size range and step size	glGetFloatv(GL_POINT_SIZE_RANGE, sizes);	glGetFloatv(GL_POINT_SIZE_GRANULARITY, &step);	// Set the initial point size	curSize = sizes[0];	// Set beginning z coordinate	z = -50.0f;	// Call only once for all remaining points	glBegin(GL_POINTS);	z = -50.0f;	for (angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f)	{		// Calculate x and y values on the circle		x = 50.0f*sin(angle);		y = 50.0f*cos(angle);		// Specify the point size before the primitive is specified		glPointSize(curSize);		// Draw the point		glBegin(GL_POINTS);		glVertex3f(x, y, z);		glEnd();		// Bump up the z value and the point size		z += 0.5f;		curSize += step;	}	// Done drawing points	glEnd();	// Restore transformations	glPopMatrix();	// Flush drawing commands	glutSwapBuffers();}void SetupRC(){	// Black background	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);	// Set drawing color to green	glColor3f(0.0f, 1.0f, 0.0f);}void ChangeSize(GLsizei w, GLsizei h){	GLfloat nRange = 100.0f;	// Prevent a divide by zero	if (h == 0)		h = 1;	// Set Viewport to window dimensions	glViewport(0, 0, w, h);	// Reset projection matrix stack	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Establish clipping volume (left, right, bottom, top, near, far)		if (w <= h)		glOrtho(-nRange, nRange, -nRange*h / w, nRange*h / w, -nRange, nRange);	else		glOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);	// Reset Model view matrix stack	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}int main(int argc, char* argv[]){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);	glutInitWindowSize(800, 600);	glutCreateWindow("Bounce");	glutDisplayFunc(RenderScene);//顯示回調函數	glutReshapeFunc(ChangeSize);//窗口大小變形回調函數	SetupRC();	glutMainLoop();	return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南乐县| 长葛市| 彭泽县| 融水| 铁岭县| 青州市| 洪雅县| 惠州市| 阿合奇县| 潜江市| 宁强县| 大余县| 紫阳县| 岐山县| 西和县| 额济纳旗| 东乡族自治县| 尤溪县| 杭州市| 安阳市| 星座| 临夏市| 那曲县| 达孜县| 米易县| 宜黄县| 万全县| 沾益县| 密云县| 丰县| 资兴市| 墨脱县| 无极县| 云和县| 建湖县| 元江| 扬中市| 罗源县| 宜宾县| 若尔盖县| 连云港市|