织梦CMS - 轻松建站从此开始!

罗索

opengl/glut的若干函数

落鹤生 发布于 2011-04-22 10:52 点击:次 
一直对opengl有兴趣,可是到现在还是略懂而已。现在才算是明白如何把opengl那套原始的屏幕坐标转换为我所熟悉的坐标系统。
TAG:

一直对opengl有兴趣,可是到现在还是略懂而已。
现在才算是明白如何把opengl那套原始的屏幕坐标转换为我所熟悉的坐标系统

先弄个小例子

  1. #include <stdlib.h> 
  2. #include <GL/glut.h> 
  3.  
  4. void init(void
  5. glClearColor (0.5, 0.5, 0.0, 0.0); 
  6. glShadeModel (GL_SMOOTH); 
  7. glLoadIdentity(); 
  8. gluOrtho2D(0,100,0,100); 
  9.  
  10. void display(void
  11. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
  12. glLoadIdentity(); 
  13. gluOrtho2D(0,100,0,100); 
  14.  
  15. glBegin(GL_TRIANGLES); 
  16. glScalef(5.0,5.0,5.0); 
  17. glColor3f(1.0,0.0,0.0); 
  18. glVertex2f(50.0,75.0); 
  19. glColor3f(0.0,1.0,0.0); 
  20. glVertex2f(50.0,25.0); 
  21. glColor3f(0.0,0.0,1.0); 
  22. glVertex2f(25.0,0.0); 
  23. glEnd(); 
  24.  
  25. glFlush (); 
  26.  
  27. void keyboard(unsigned char key, int x, int y) 
  28. switch (key) 
  29. case 27: 
  30. exit(0); 
  31. break
  32.  
  33. int main(int argc, char** argv) 
  34. glutInit(&argc, argv); 
  35. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 
  36. glutInitWindowSize (400, 400); 
  37. glutInitWindowPosition (0, 0); 
  38. glutCreateWindow (argv[0]); 
  39. init (); 
  40. glutDisplayFunc(display); 
  41. glutKeyboardFunc(keyboard); 
  42. glutMainLoop(); 
  43. return 0; 

呵呵 这都是gluOrtho2D的功劳啊

这里给出我所熟悉的一组函数
1.gluOrtho2D — define a 2D orthographic projection matrix
void gluOrtho2D(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top);
该函数就是把屏幕左下角坐标设计为left, bottom,右上角设置为 top,right

2. void glTranslatef(GLfloat x,GLfloat y,GLfloat z)
该函数用来平移图像
当然它还有向量版本

3. void glRotatef(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)
该函数用来翻转图像,第一个参数是角度
例如glRotatef(45,0,0,1.0);
把图像研z轴翻转45角度

4. void glScalef(GLfloat x, GLfloat y, GLfloat z);
是采用来缩放图像的函数

附注:
去年开始接触opengl现在还是这个水平 -_-!

(ccsdu2004)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201104/11270.html]
本文出处:CSDN博客 作者:ccsdu2004
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容