opengl/glut的若干函数

一直对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现在还是这个水平 -_-!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值