OpenGL 学习笔记3_1(绘制点相关)
来源:互联网 发布:环形网络拓扑结构图 编辑:程序博客网 时间:2024/06/05 18:16
蓝宝书 第三章
画点 Point1)单个点
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 zeroif (h == 0)h = 1;// Set Viewport to window dimensionsglViewport(0, 0, w, h);// Reset projection matrix stackglMatrixMode(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);elseglOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);// Reset Model view matrix stackglMatrixMode(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 colorglClear(GL_COLOR_BUFFER_BIT);// Save matrix state and do the rotationglPushMatrix();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 pointsglBegin(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 littleglVertex3f(x, y, z);z += 0.5f;}// Done drawing pointsglEnd();// Restore transformationsglPopMatrix();// Flush drawing commandsglutSwapBuffers();}void SetupRC(){// Black backgroundglClearColor(0.0f, 0.0f, 0.0f, 1.0f);// Set drawing color to greenglColor3f(0.0f, 1.0f, 0.0f);}void ChangeSize(GLsizei w, GLsizei h){GLfloat nRange = 100.0f;// Prevent a divide by zeroif (h == 0)h = 1;// Set Viewport to window dimensionsglViewport(0, 0, w, h);// Reset projection matrix stackglMatrixMode(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);elseglOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);// Reset Model view matrix stackglMatrixMode(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 anglesGLfloat sizes[2]; // Store supported point size rangeGLfloat step; // Store supported point size incrementsGLfloat curSize; // Store current point size// Clear the window with current clearing colorglClear(GL_COLOR_BUFFER_BIT);// Save matrix state and do the rotationglPushMatrix();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 sizeglGetFloatv(GL_POINT_SIZE_RANGE, sizes);glGetFloatv(GL_POINT_SIZE_GRANULARITY, &step);// Set the initial point sizecurSize = sizes[0];// Set beginning z coordinatez = -50.0f;// Call only once for all remaining pointsglBegin(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 circlex = 50.0f*sin(angle);y = 50.0f*cos(angle);// Specify the point size before the primitive is specifiedglPointSize(curSize);// Draw the pointglBegin(GL_POINTS);glVertex3f(x, y, z);glEnd();// Bump up the z value and the point sizez += 0.5f;curSize += step;}// Done drawing pointsglEnd();// Restore transformationsglPopMatrix();// Flush drawing commandsglutSwapBuffers();}void SetupRC(){// Black backgroundglClearColor(0.0f, 0.0f, 0.0f, 1.0f);// Set drawing color to greenglColor3f(0.0f, 1.0f, 0.0f);}void ChangeSize(GLsizei w, GLsizei h){GLfloat nRange = 100.0f;// Prevent a divide by zeroif (h == 0)h = 1;// Set Viewport to window dimensionsglViewport(0, 0, w, h);// Reset projection matrix stackglMatrixMode(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);elseglOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);// Reset Model view matrix stackglMatrixMode(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;}
0 0
- OpenGL 学习笔记3_1(绘制点相关)
- OpenGL 学习笔记3_2(绘制线相关)
- OpenGL 学习笔记3_3(绘制三角形相关)
- OpenGL 学习笔记3_4(绘制多边形相关)
- OpenGL学习笔记4_1(矩阵相关)
- opengl学习笔记(三)-点和线段的绘制
- openGL学习笔记三 : 绘制点、线以及多边形
- Android OpenGL ES学习笔记之绘制点
- OpenGL绘制球形相关学习
- opengl学习笔记3-1-在3D中绘制点
- opengl学习笔记3-3-绘制三角形
- OpenGL 学习笔记(3)绘制几何物体
- OpenGL 学习笔记(3)绘制几何物体
- 学习OpenGL(三)绘制点
- opengl点的绘制
- Opengl绘制点
- 【OpenGL】绘制一个点
- OpenGL 学习笔记绘制几何物体
- WRONGTYPE Operation against a key holding the wrong kind of value
- 对LOWORD, HIWORD, LOBYTE, HIBYTE的理解
- 可穿戴手势识别控制器
- 模仿微博ViewPage指示器滑动效果的自定义View
- Android6.0开机时SIM卡开机初始化
- OpenGL 学习笔记3_1(绘制点相关)
- JAVASE基础-day14(常见对象(正则,Math..))
- Qt5.6作浏览器Demo可查看地图
- java构造代码块详解
- 欢迎使用CSDN-markdown编辑器
- 排序算法总结
- CentOS 7加载B120i驱动
- POJ2342 Anniversary party 【树形dp】
- nginx 升级