Skaveelicious
Skaveelicious

Reputation: 33

Understanding glTexCoord2f(), glVertex3f() in OpenGL

I'm trying to build in OculusRift support into our car simulator software at our institute. Due to the way the simulator software is setup we decided to fix the distortion due to the lenses client side build a display list with OpenGL to run the first tests.

Basically where I'm struggly a bit is understanding how OpenGL does the drawing (for the display list). I used the info from different tutorials and if I understand it correctly the following for-loop would select the coordinates for Tex 0,1,2 do some vignetting and bind it to each vetice. The glBegin(GL_TRIANGLES) would automatically draw triangles out of the vertices.

The coordinates of the vertices are stored in a struct the address ov is pointing to. Additionally we have offsets for each color channel.

Is the following code snipped from a OpenGL viewpoint correct?

ovrHmd_CreateDistortionMesh(pHmd, eyeRenderDesc[eyeNum].Eye, eyeRenderDesc[eyeNum].Fov,
ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette, &meshData);

ovrDistortionVertex * ov = meshData.pVertexData;

// New compiled distortion-rendering display list
glNewList(drList, GL_COMPILE);

// Make triangles out of the vertices
glBegin(GL_TRIANGLES);

for (unsigned int vertNum = 0; vertNum < meshData.VertexCount; vertNum++) {
    // Tex0,1,2 have already been activated
    glMultiTexCoord2f(GL_TEXTURE0, ov->TanEyeAnglesR.x, ov->TanEyeAnglesR.y);
    glMultiTexCoord2f(GL_TEXTURE1, ov->TanEyeAnglesG.x, ov->TanEyeAnglesG.y);
    glMultiTexCoord2f(GL_TEXTURE2, ov->TanEyeAnglesB.x, ov->TanEyeAnglesB.y);
    glColor4f(
    (OVR::UByte)(ov->VignetteFactor * 255.99f),
    (OVR::UByte)(ov->VignetteFactor * 255.99f),
    (OVR::UByte)(ov->VignetteFactor * 255.99f),
    (OVR::UByte)(ov->TimeWarpFactor * 255.99f));
    glVertex3f(ov->ScreenPosNDC.x, ov->ScreenPosNDC.y, 0.5); // z: constant
    ov++;
}

glEnd();
glEndList();

Upvotes: 0

Views: 1827

Answers (2)

Jherico
Jherico

Reputation: 29240

glColor4f(
  (OVR::UByte)(ov->VignetteFactor * 255.99f),
  (OVR::UByte)(ov->VignetteFactor * 255.99f),
  (OVR::UByte)(ov->VignetteFactor * 255.99f),
  (OVR::UByte)(ov->TimeWarpFactor * 255.99f));

glColor4f expects floating point values clamped between 0 and 1. However, you are passing it bytes. Perhaps you're confusing it with glColor4b?

Upvotes: 0

datenwolf
datenwolf

Reputation: 162164

I'm trying to build in OculusRift support into our car simulator software at our institute. Due to the way the simulator software is setup we decided to fix the distortion due to the lenses client side build a display list with OpenGL to run the first tests.

Stop right there! You're targeting a VR display, which means you must use the highest performance drawing method you can get to draw dynamic meshes (required for the timewarping). Display Lists can't do this. Actually the immediate mode (glBeginglEnd) creates lots of CPU overhead which is exactly what you don't want to have.

Upvotes: 1

Related Questions