opengl学习笔记(2)
来源:互联网 发布:无人机淘宝可靠吗 编辑:程序博客网 时间:2024/05/01 14:22
setup a Window with GLUT
glutInit (&argc, argv); //initialize the program.
glutInitWindowSize (500, 500); //set the width and height of the window
glutInitWindowPosition (100, 100); //set the position of the window
glutCreateWindow ("A basic OpenGL Window"); //set the caption for the window
glutDisplayFunc (display); //call the display function to draw our world
glutMainLoop (); //initialize the OpenGL loop cycle
==================================================================================================================
So thus far, we have a window. But the display method that I mentioned is needed. Lets take a look at this and dissect it.
void display (void) {
glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
glClear (GL_COLOR_BUFFER_BIT); //Clear teh Color Buffer (more buffers later on)
glLoadIdentity(); //load the Identity Matrix
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
glFlush(); //flush it all to the screen
}
2. The next thing we want to do, is erase everything currently stored by OpenGL. We need to do this at the start of the method, as the method keeps looping over itself and if we draw something, we need to erase it before we draw our next frame. If we don't do this, we can end up with a big mess inside our buffer where frames have been drawn over each other.
3. The third method, glLoadIdentity resets our model view matrix to the identity matrix, so that our drawing transformation matrix is reset.
From then, we will set the 'camera' for our scene. I am placing it 5 units back into the user so that anything we draw at 0,0,0 will be seen infront of us.
4. The final thing we need to do is then flush the current buffer to the screen so we can see it. This can be done with glFlush() as we are only using a single buffer.
/*
Here is your first OpenGL tutorial. How to make a Window.
First off you need to call the OpenGL header files. The basics are
gl.h and glut.h, with these two your program will run on whatever OS
it is compiled in as it does not currently rely on Windows.
So that you know, the gl.h supplies the openGL commands while glut.h
allows us to call the glut commands. If you are not using glut, then
do not bother to call this.
After this next little bit, the rest of the code is explained below in the actual code.
To reshape a window in GLUT you need one command in the 'main' function
this is:
glutInitWindowSize (500, 500);
this will set it to 500 pixels wide and 500 high.
The other line you may notice I have added is:
glutInitWindowPosition (100, 100);
This sets where the window is located on the screen, in this case
100 pixels down and 100 to the right.
*/
#include <GL/glut.h> //include the glut header file
void display (void) {
glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
glClear (GL_COLOR_BUFFER_BIT); //Clear the Color Buffer (more buffers later on)
glLoadIdentity(); //load the Identity Matrix
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
glFlush(); //flush it all to the screen
}
int main (int argc, char **argv) {
glutInit (&argc, argv); //initialize the program.
glutInitDisplayMode (GLUT_SINGLE); //set up a basic display buffer (only singular for now)
glutInitWindowSize (500, 500); //set the width and height of the window
glutInitWindowPosition (100, 100); //set the position of the window
glutCreateWindow ("A basic OpenGL Window"); //create the window and set the caption for the window
glutDisplayFunc (display); //call the display function to draw our world
glutMainLoop (); //initialize the OpenGL loop cycle
return 0;
}
- opengl学习笔记(2)
- OpenGL学习笔记2
- opengl学习笔记(2)
- OpenGL学习笔记2
- OpenGL 学习笔记2
- openGL 学习笔记 2
- Android的OpenGL学习笔记(2)
- openGL学习笔记2(颜色)
- 初识openGL---openGL学习笔记(一)
- openGL画线---openGL学习笔记(三)
- Opengl学习笔记(一)
- OpenGL学习笔记(一)
- OpenGL学习笔记(二)
- OpenGL学习笔记(三)
- OpenGL学习笔记(四)
- OpenGL学习笔记(一)
- OpenGL学习笔记(二)
- OpenGL 学习笔记(一)
- go 解析XML 设置缺省att的默认值
- [转发][纯记录]raid组的初始化详解
- Selection sort 选择排序
- PHP调试网页出现乱码解决方法!
- OpenCV视频进度播放控制
- opengl学习笔记(2)
- pl_sql
- 得到view的信息以及 view绘制流程解析
- JAVA高并发学习笔记(四) 无锁
- check tech
- 高效编程
- Cocos2d-x中使用Socket方法总结
- sql_answer
- sql_question