05-20-2014 04:09 AM
uniform mat4 mvp_matrix;
attribute vec4 a_position;
attribute vec2 a_texcoord;
varying vec2 v_texcoord;
//! [0]
void main()
{
// Calculate vertex position in screen space
gl_Position = mvp_matrix * a_position;
// Pass texture coordinate to fragment shader
// Value will be automatically interpolated to fragments inside polygon faces
v_texcoord = a_texcoord;
}
uniform sampler2D texture;
varying vec2 v_texcoord;
//! [0]
void main()
{
// Set fragment color from texture
gl_FragColor = texture2D(texture, v_texcoord);
}
void GeometryEngine::initSphereGeometry(float hfov, float vfov) {
float rHFov = hfov * M_PI / 180;
float rVFov = vfov * M_PI / 180;
QVector<GLfloat> data;
for (int i = 0; i <= NUM_PARALLELS; i++) {
float v0 = (i - 1) / (float)(NUM_PARALLELS);
float lat0 = rVFov * (-0.5f + v0);
float z0 = sinf(lat0);
float zr0 = cosf(lat0);
float v1 = i / (float)(NUM_PARALLELS);
float lat1 = rVFov * (-0.5f + v1);
float z1 = sinf(lat1);
float zr1 = cosf(lat1);
for (int j = 0; j <= NUM_MERIDIANS; j++) {
float u = (j - 1) / (float)NUM_MERIDIANS;
float lng = rHFov * u;
float x = cosf(lng);
float y = sinf(lng);
data.push_back(x * zr0); //X
data.push_back(y * zr0); //Y
data.push_back(z0); //Z
data.push_back(u); //U
data.push_back(v0); //V
data.push_back(x * zr1); //X
data.push_back(y * zr1); //Y
data.push_back(z1); //Z
data.push_back(u); //U
data.push_back(v1); //V
}
}
vbo.bind();
vbo.allocate(&data.front(), data.size() * 4);
vbo.release();
}
void GeometryEngine::drawSphereGeometry(QGLShaderProgram *program) {
vbo.bind();
int vertexLocation = program->attributeLocation("a_position");
program->enableAttributeArray(vertexLocation);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
int texcoordLocation = program->attributeLocation("a_texcoord");
program->enableAttributeArray(texcoordLocation);
glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (const void*)(3 * sizeof(float)));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 2 * (NUM_PARALLELS + 1) * (NUM_MERIDIANS + 1));
vbo.release();
}
program.setUniformValue("texture", 1);but I only get a black sphere.
05-20-2014 01:05 PM
05-21-2014 01:13 AM
07-10-2014 01:18 AM
Did this answer your question? If it didn’t, use our search to find other topics or create your own and other members of the community will help out.
If you need an agent to help with your Meta device, please contact our store support team here.
Having trouble with a Facebook or Instagram account? The best place to go for help with those accounts is the Facebook Help Center or the Instagram Help Center. This community can't help with those accounts.
Check out some popular posts here:
Getting Help from the Meta Quest Community
Tips and Tricks: Charging your Meta Quest Headset