Note that there are some explanatory texts on larger screens.

plurals
  1. POTexture coordinates for a skybox
    text
    copied!<p>I'm attempting to map a sky box texture that looks like <a href="http://www.keithlantz.net/wp-content/uploads/2011/10/skybox_texture.jpg" rel="nofollow">this</a></p> <p>I am creating a 3d cube that is drawn using GL_TRIANGLES and have 8 vertices and 8 colors for the vertices. I can post the code if need be. </p> <pre><code>bool Skybox::onInitialize() { myRadius = 100; setPosition(Vector3(0.0f, 2.0f, 0.0f)); //Initialize color matrix myColors.push_back(Color(1.0f, 0.0f, 0.0f, 1.0f)); myColors.push_back(Color(1.0f, 1.0f, 0.0f, 1.0f)); myColors.push_back(Color(1.0f, 0.5f, 0.0f, 1.0f)); myColors.push_back(Color(0.5f, 0.5f, 0.5f, 1.0f)); myColors.push_back(Color(1.0f, 0.0f, 0.0f, 1.0f)); myColors.push_back(Color(1.0f, 1.0f, 0.0f, 1.0f)); myColors.push_back(Color(1.0f, 0.5f, 0.0f, 1.0f)); myColors.push_back(Color(0.5f, 0.5f, 0.5f, 1.0f)); //Position the key points of the cube myVertices.push_back(Vertex(-myRadius, -myRadius, myRadius));//0 myVertices.push_back(Vertex(-myRadius, -myRadius, -myRadius));//1 myVertices.push_back(Vertex(myRadius, -myRadius, -myRadius));//2 myVertices.push_back(Vertex(myRadius, -myRadius, myRadius));//3 myVertices.push_back(Vertex(-myRadius, myRadius, myRadius));//4 myVertices.push_back(Vertex(-myRadius, myRadius, -myRadius));//5 myVertices.push_back(Vertex( myRadius, myRadius, -myRadius));//6 myVertices.push_back(Vertex( myRadius, myRadius, myRadius));//7 //Push back the indices that make up the triangles for each face. //Bottom myIndices.push_back(3); myIndices.push_back(2); myIndices.push_back(0); myIndices.push_back(2); myIndices.push_back(1); myIndices.push_back(0); //Top myIndices.push_back(4); myIndices.push_back(6); myIndices.push_back(7); myIndices.push_back(4); myIndices.push_back(5); myIndices.push_back(6); //Front myIndices.push_back(1); myIndices.push_back(4); myIndices.push_back(0); myIndices.push_back(1); myIndices.push_back(5); myIndices.push_back(4); //Back myIndices.push_back(3); myIndices.push_back(6); myIndices.push_back(2); myIndices.push_back(3); myIndices.push_back(7); myIndices.push_back(6); //Side myIndices.push_back(5); myIndices.push_back(1); myIndices.push_back(6); myIndices.push_back(1); myIndices.push_back(2); myIndices.push_back(6); //Side myIndices.push_back(4); myIndices.push_back(7); myIndices.push_back(0); myIndices.push_back(7); myIndices.push_back(3); myIndices.push_back(0); ////Generate Texture Coordinates //Bottom myTexCoords.push_back(TexCoord(0.25, 0)); myTexCoords.push_back(TexCoord(0.25, 0.375)); myTexCoords.push_back(TexCoord(0.5, 0.375)); myTexCoords.push_back(TexCoord(0.5, 0)); //Top myTexCoords.push_back(TexCoord(0.25, 1)); myTexCoords.push_back(TexCoord(0.25, 0.625)); myTexCoords.push_back(TexCoord(0.5, 0.625)); myTexCoords.push_back(TexCoord(0.5, 1)); ////Left //myTexCoords.push_back(TexCoord(0, 0.625)); //myTexCoords.push_back(TexCoord(0.25, 0.625)); //myTexCoords.push_back(TexCoord(0.25, 0.375)); //myTexCoords.push_back(TexCoord(0, 0.375)); ////Right //myTexCoords.push_back(TexCoord(0.5, 0.625)); //myTexCoords.push_back(TexCoord(0.75, 0.625)); //myTexCoords.push_back(TexCoord(0.75, 0.375)); //myTexCoords.push_back(TexCoord(0.5, 0.375)); ////Back //myTexCoords.push_back(TexCoord(0.75, 0.625)); //myTexCoords.push_back(TexCoord(1.0, 0.625)); //myTexCoords.push_back(TexCoord(1.0, 0.375)); //myTexCoords.push_back(TexCoord(0.75, 0.375)); const string vertexShader = (GLSLProgram::glsl130Supported()) ? VERTEX_SHADER_130 : VERTEX_SHADER_120; const string fragmentShader = (GLSLProgram::glsl130Supported()) ? FRAGMENT_SHADER_130 : FRAGMENT_SHADER_120; if (!myTexture.load(SKY_TEXTURE)) { std::cerr &lt;&lt; "Could not load the particle texture" &lt;&lt; std::endl; return false; } glGenTextures(1, &amp;myTexID); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, myTexID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myTexture.getWidth(), myTexture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myTexture.getImageData()); m_shaderProgram = std::auto_ptr&lt;GLSLProgram&gt;(new GLSLProgram(vertexShader, fragmentShader)); if (!m_shaderProgram-&gt;initialize()) { std::cerr &lt;&lt; "Could not load the skybox shaders" &lt;&lt; std::endl; return false; } m_shaderProgram-&gt;bindAttrib(0, "a_Vertex"); m_shaderProgram-&gt;bindAttrib(1, "a_Color"); m_shaderProgram-&gt;bindAttrib(2, "a_TexCoord0"); m_shaderProgram-&gt;linkProgram(); //m_shaderProgram-&gt;sendUniform("texture0", 0); glGenBuffers(1, &amp;myVertexBuffer); //Generate a buffer for the vertices glBindBuffer(GL_ARRAY_BUFFER, myVertexBuffer); //Bind the vertex buffer glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * myVertices.size(), &amp;myVertices[0], GL_STATIC_DRAW); //Send the data to OpenGL glGenBuffers(1, &amp;myColorBuffer); glBindBuffer(GL_ARRAY_BUFFER, myColorBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(Color) * myColors.size(), &amp;myColors[0], GL_STATIC_DRAW); //Send the data to OpenGL glGenBuffers(1, &amp;myTexCoordBuffer); glBindBuffer(GL_ARRAY_BUFFER, myTexCoordBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoord) * myTexCoords.size(), &amp;myTexCoords[0], GL_STATIC_DRAW); //Send the data to OpenGL glGenBuffers(1, &amp;myIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, myIndexBuffer); //Bind the vertex buffer glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * myIndices.size(), &amp;myIndices[0], GL_STATIC_DRAW); //Send the data to OpenGL return true; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload