opengl/glut的若干函数

来源:互联网 发布:淘宝买家秀兼职骗局 编辑:程序博客网 时间:2024/04/30 16:03
一直对opengl有兴趣,可是到现在还是略懂而已。
现在才算是明白如何把opengl那套原始的屏幕坐标转换为我所熟悉的坐标系统

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

呵呵 这都是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现在还是这个水平 -_-!
原创粉丝点击