OpenGL基于glfw库的画点、画线、画三角
2017-04-01 17:44
1786 查看
1)glVertex函数
参考:http://www.cnblogs.com/mattins/articles/4081970.html
2)坐标系
http://blog.csdn.net/meegomeego/article/details/8686816
代码如下:
运行一下!
参考:
OpenGL简单画线程序
GLFW初体验
OpenGL绘制点
GLFW--Getting started
参考:http://www.cnblogs.com/mattins/articles/4081970.html
2)坐标系
http://blog.csdn.net/meegomeego/article/details/8686816
代码如下:
#include <GLFW/glfw3.h> void drawPoint() { /* Draw a point */ glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glPointSize(2.0f); glBegin(GL_POINTS); glColor3f(1.0, 0.0, 0.0); // Red glVertex2f(0.0f,0.0f); glVertex2f(0.5f,0.8f); glEnd(); } void drawLint() { glClearColor (0.0, 0.0, 0.0, 0.0); glClear (GL_COLOR_BUFFER_BIT); glLineWidth(2);//设置线段宽度 glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex2f(0.8,1); //定点坐标范围 glVertex2f(0,-1); glEnd(); } void drawTriangle() { glClearColor (0.0, 0.0, 0.0, 0.0); glClear (GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); // Red glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); // Green glVertex3f(-1.0, -1.0, 0.0); glColor3f(0.0, 0.0, 1.0); // Blue glVertex3f(1.0, -1.0, 0.0); glEnd(); } int main(void) { GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /*your draw*/ // drawPoint(); // drawLint(); drawTriangle(); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }
运行一下!
参考:
OpenGL简单画线程序
GLFW初体验
OpenGL绘制点
GLFW--Getting started
相关文章推荐
- VS2012下基于Glut OpenGL GL_TRIANGLE_FAN示例程序:
- 基于OpenGL的3D天空仿真
- 基于MFC的OpenGL绘图
- VS2012下基于Glut OpenGL GL_QUADS示例程序:
- 新做的一个基于OPENGL的gui库
- VS2012下基于Glut OpenGL glScissor示例程序:
- VS2015配置OpenGL(GLFW库)
- 机器人运动学(资料与源代码)-----基于OpenGL的三维重建
- 基于OpenGL的3D天空仿真
- 基于Kinect-OpenNI-OpenCV-OpenGL的环境三维重构
- android上用opengl画线
- [OpenGL]基于点云的植物建模
- 基于MFC对话框的OpenGL三维图形开发
- 基于OpenGL实现的多段Bezier曲线拼接
- 基于ffmpeg+opengl+opensl es的android视频播放器
- Spherical Harmonics Lighting的代码实现(基于OpenGL)
- 【C#/OpenGL】基于DEM数据的3D地形绘制(基于CSGL)
- 基于OpenGL和OpenCV的三维显示
- 基于Kinect-OpenNI-OpenCV-OpenGL的环境三维重构 windows vs2008 深度彩色图像
- 基于VC++的OpenGL编程讲座之坐标变换(1)