opengl 回调函数调用类中的成员函数

来源:互联网 发布:淘宝店铺开店教程视频 编辑:程序博客网 时间:2024/04/29 05:40

介绍:如何使用静态库,以及静态函数。

This article introduces static and its Function,IF you want to know more , you can visit - - - > 李sir

example follows:

line.h

//line.h#pragma once#include <gl/glut.h>class Line{public:    void init();    static void display();    /*    *  如果写成 void displayer(), 错误如下:    *  C3867    “Line::display”: 非标准语法;请使用 "&" 来创建指向成员的指针    */};

line.cpp

//line.cpp#include "line.h"void Line::init(){    glClearColor(1.0, 1.0, 1.0, 0);    glMatrixMode(GL_PROJECTION);    gluOrtho2D(0, 300, 0, 400);}void Line::display(){    GLdouble de1[2] = { 50, 50 };    GLdouble de2[2] = { 200, 200 };    glClear(GL_COLOR_BUFFER_BIT);    glColor3f(0.3, 0.5, 0.7);    glLineWidth(50);    glBegin(GL_LINES);    glVertex2dv(de1);    glVertex2dv(de2);    glEnd();    glFlush();}

main.cpp

//main.cpp#include "line.h"int main(int acgr, char** acgv){    glutInit(&acgr, acgv);    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);    glutInitWindowSize(300, 400);    glutInitWindowPosition(0, 0);    glutCreateWindow("he,judy");    Line line;    line.init();    /**************/    glutDisplayFunc(line.display);  // 回调函数    /**************/    glutMainLoop();    return 0;}
0 0
原创粉丝点击