opengl3中的立方体纹理

时间:2012-12-16 21:58:06

标签: java opengl textures texture-mapping opengl-3

只是做我的计算机图形分配 - 将纹理(600x400位图具有不同的数字)放在立方体上以形成一个合适的骰子。我设法使用“经典”纹理映射:创建验证并为其添加相应的纹理坐标:

int arrayindex = 0;
float xpos = 0.0f;
float xposEnd = 0.32f;
float ypos = 0.0f;
float yposEnd = 0.49f;
int count = 0;
void quad( int a, int b, int c, int d ) {
    colors[arrayindex] = vertex_colors[a];
    points[arrayindex] = vertices[a];
    tex_coord[arrayindex] = new Point2(xpos, ypos);
    arrayindex++;
    colors[arrayindex] = vertex_colors[b];
    points[arrayindex] = vertices[b];
    tex_coord[arrayindex] = new Point2(xpos, yposEnd);
    arrayindex++;
    colors[arrayindex] = vertex_colors[c];
    points[arrayindex] = vertices[c];
    tex_coord[arrayindex] = new Point2(xposEnd, yposEnd);
    arrayindex++;
    colors[arrayindex] = vertex_colors[a];
    points[arrayindex] = vertices[a];
    tex_coord[arrayindex] = new Point2(xpos, ypos);
    arrayindex++;
    colors[arrayindex] = vertex_colors[c];
    points[arrayindex] = vertices[c];
    tex_coord[arrayindex] = new Point2(xposEnd, yposEnd);
    arrayindex++;
    colors[arrayindex] = vertex_colors[d];
    points[arrayindex] = vertices[d]; 
    tex_coord[arrayindex] = new Point2(xposEnd, ypos);
    arrayindex++;
    xpos = xpos + 0.34f;
    xposEnd = xpos + 0.32f;
    count++;
    if (count == 3) {
        xpos = 0.0f;
        xposEnd = 0.33f;
        ypos = 0.51f;
        yposEnd = 1.0f;
    }
}

void colorcube() {
    quad( 1, 0, 3, 2 );
    quad( 2, 3, 7, 6 );
    quad( 3, 0, 4, 7 );
    quad( 6, 5, 1, 2 );
    quad( 5, 4, 0, 1 );
    quad( 4, 5, 6, 7 );

    pointsBuf = VectorMath.toBuffer(points);
    colorsBuf = VectorMath.toBuffer(colors);
    texcoord = VectorMath.toBuffer(tex_coord);
}

将所有这些内容传递给着色器并将其组合在一起。

但是在审查幻灯片时我注意到这种方法应该是“pre opengl3”。 有没有其他方法来做这些事情?

在讲座示例中,我注意到它在顶点着色器中放在一起,但它只是用于简单的2d平面,而不是3d立方体

tex_coords = vec2(vPosition.x+0.5,vPosition.z+0.5);

然后传递给片段着色器以创建纹理。

1 个答案:

答案 0 :(得分:1)

  

但是在审查幻灯片时,我注意到这种方法应该是“pre opengl3”。

我认为你的幻灯片是指旧的立即模式。在立即模式中,通过调用立即绘制它们的函数将每个顶点及其属性发送到OpenGL。

在您的代码中,您正在使用顶点数据初始化缓冲区。此缓冲区可能然后作为一个整体传递给OpenGL,并通过一次OpenGL调用作为批处理绘制。我写了“ may ”,因为你的问题中没有一个OpenGL调用。

相关问题