0

我正在尝试制作一个显示GLuint纹理的函数。这是我到目前为止所做的。它应该输出一个白色四边形,但它只是崩溃:

position2 Q_pos[4]={{0,0},
                    {1,0},
                    {1,1},
                    {0,1}};
void blit_texture(GLuint texture,Point mid_pt,Point Scale=Point(1,1,1),
    Point rotate_angle=Point(0,0),Point focus_point=Point(0,0))
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glPushMatrix();
    GLtranslate2v(mid_pt);
    GLrotate3f(rotate_angle);
    GLtranslate2v(focus_point);
    glScalef(Scale.x,Scale.y,1);
        glColor4f(1,1,1,1);
        glVertexPointer( 2, GL_FLOAT, 0, Q_pos );
        glDrawArrays( GL_QUADS, 0, 4 );

    glPopMatrix();
    glDisableClientState(GL_VERTEX_ARRAY);
}

我还对点进行了一些定义,更容易旋转等......:

#define GLrotate3f(pt) glRotatef(pt.x,1,0,0),glRotatef(pt.y,0,1,0),glRotatef(pt.z,0,0,1)
#define GLtranslate2v(pt) glTranslatef(pt.x,pt.y,0);
#define GLscale2v(pt) glScalef(pt.x,pt.y,0);
class position3
{
    public:
    float x,y,z;
    position3(float X=0,float Y=0,float Z=0){
    x=X,y=Y,z=Z;}
    void operator=(float num){x=num,y=num,z=num;}
    void operator=(position3 pt){
                             x=pt.x,y=pt.y,z=pt.z;
                                }
    bool operator>(float Min)
    {
        if (x<Min || y<Min || z<Min) return 0;
        return 1;
    }
    bool operator<(float Max)
    {
        if (x>Max || y>Max || z>Max) return 0;
        return 1;
    }
};
class position2
{
    public:
    float x,y;
    position2(float X=0,float Y=0)
    {
    x=X,y=Y;
    }
    void operator=(float num){x=num,y=num;}
    void operator=(position2 pt){
                             x=pt.x,y=pt.y;
                                }
    bool operator>(float Min)
    {
        if (x<Min || y<Min) return 0;
        return 1;
    }
    bool operator<(float Max)
    {
        if (x>Max || y>Max) return 0;
        return 1;
    }
};
class color3f
{
    public:
    float r,g,b;
    color3f(float R=0,float G=0,float B=0){
    r=R,g=G,b=B;}
    void operator=(color3f cl)
    {
    r=cl.r,g=cl.g,b=cl.b;
    }
};
class Point : public position3 , public color3f
{
public:
Point(float X=0,float Y=0,float Z=0,float R=0,float G=0,float B=0)
{
    x=X,y=Y,z=Z;
    r=R,g=G,b=B;
}
};

如果我在中间模式下制作它工作正常,甚至纹理也会出现,但是当我尝试使用 VA 时,它无法制作单个白色四边形。

我对其进行了一些调试,发现如果我exit(42);glDrawArrays()调用之前放置它会返回 42 但如果我glDrawArrays()在程序崩溃后使用它,那么问题似乎是由glDrawArrays().

这是我的初始化:

const int width=640, height=480;
glViewport(0,0,width, height );
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, ((GLfloat)-1), (GLfloat)1);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

另外,有没有一种方法可以检查是否支持 VBO?这是因为我用他们制作了一个程序,它在我的电脑上运行良好(使用 OpenGL 4.2),但是当我试图在我朋友的电脑上运行它(使用 OpenGL 2.1)时它崩溃了。

4

0 回答 0