画点的例子:
#include "stdafx.h" #include<gl/glut.h> #include<cmath> // Define a constant for the value of PI #define GL_PI 3.1415f // Rotation amounts static GLfloat xRot = 0.0f; static GLfloat yRot = 0.0f; // Called to draw scene void RenderScene(void) { GLfloat x,y,z,angle; // Storeage 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(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.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) { x = 30.0f*sin(angle); y = 40.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(); } // This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to green glColor3f(1.0f, 0.0f, 0.0f); } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) xRot-= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key > 356.0f) xRot = 0.0f; if(key < -1.0f) xRot = 355.0f; if(key > 356.0f) yRot = 0.0f; if(key < -1.0f) yRot = 355.0f; // Refresh the Window glutPostRedisplay(); } void ChangeSize(int w, int 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_RGB | GLUT_DEPTH); glutCreateWindow("Points Example"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); SetupRC(); glutMainLoop(); return 0; }
效果:
相关推荐
在VC中实现OpenGL三维绘图,MFC中使用opengl。
android opengl入门 画点 画图
OpenGL绘图相关函数,很不错哦,给大家推荐一下!!!
基于MFC的OpenGL绘图设置说明 。。。。。。
OpenGL绘图软件源代码 包含2D基本图形的绘制
在VC中实现OpenGL三维绘图,很适合opengl的初学者使用!是初学者的必备源码!
OpenGL绘图示例,方便学习OpenGL的人对OpenGL有个初步了解。
此资源,采用qtcreator opengl技术,显示2d的图片,可以修改利用opengl显示多张图片
AndroidOpenGL纹理绘图,添加了非常详细的注释
C#语言开发OpenGL图形处理的必备场景搭建。用户下载解压后可直接运行,代码简洁便于理解。
简单的OpenGL 3D绘图程序 初学者必学
VC实现OpenGL三维绘图
opengl的简单绘图程序 运行时需要将gl的头文件以及源文件拷贝到环境中去
创建一个基于MFC 的Single Document 应用程序,利用OpenGL 进行图形的绘制: 1.实现OpenGL 绘图环境和Windows 绘图环境兼容。 2.利用OpenGL 绘图函数进行一些基本图形如直线、多边形的绘制。 3.利用OpenGL 设置...
超简洁的OPENGL三维绘点控件,包括放大缩小,旋转平移,点颜色设置。接口简单。
这个程序可是算是一个绘图的计算器,使用链表和OPENGL技术 效果可以 与大家分享
OpenGL绘图程序OpenGL绘图程序OpenGL绘图程序OpenGL绘图程序OpenGL绘图程序OpenGL绘图程序
一、简介 二、MFC中的OpenGL基本框架 三、画图实例 四.小结 欢迎多多下哦~~
glad OpenGL绘图的函数索引库,版本3.3,可用于OpenGL绘图使用 在使用时将glad.c放在代码文件夹,将glad.h放在Windows Kits包含目录 然后直接include 就可以