Note that there are some explanatory texts on larger screens.

plurals
  1. POGlowing/halo effect on cube mesh using TGA file
    primarykey
    data
    text
    <p>First of all, we (my friends and I) are working on a Computer Graphics project where we are supposed to simulate particles (in our case, small cubes (mesh3d)) that would interact with each other in a space context. This is, hundreds of particles exploding and attracting each others using physics laws.</p> <p>We based our implementation on a framework provided from our school, so we have to "adapt ourselves" to it. </p> <p>While creating the cube (mesh3d), we provide a material containing a texture. </p> <pre><code>Mesh3D* SolarViewer:: createCube() { // initialize Mesh3D Mesh3D *cube = new Mesh3D(); MeshMaterial* mat = new MeshMaterial; //we create the material for the cube mat-&gt;m_diffuseTexture.create("particle.tga"); //we create the diffuse texture of the material to be particle.tga // setup uniform cube with side length 0.5 and center of cube being (0,0,0) std::vector&lt; Vector3 &gt; cubeVertices; std::vector&lt; Vector3 &gt; cubeNormals; std::vector&lt; Vector3 &gt; cubeColors; std::vector&lt; unsigned int &gt; cubeIndices; float d = 1.0; // front cubeVertices.push_back(Vector3(-d,-d, d)); cubeVertices.push_back(Vector3( d,-d, d)); cubeVertices.push_back(Vector3( d, d, d)); cubeVertices.push_back(Vector3(-d, d, d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(0,0,1)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.8,0.3,0.3)); cubeIndices.push_back(0); cubeIndices.push_back(1); cubeIndices.push_back(2); cubeIndices.push_back(0); cubeIndices.push_back(2); cubeIndices.push_back(3); // right cubeVertices.push_back(Vector3( d,-d,-d)); cubeVertices.push_back(Vector3( d,-d, d)); cubeVertices.push_back(Vector3( d, d, d)); cubeVertices.push_back(Vector3( d, d,-d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(1,0,0)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.3,0.8,0.3)); cubeIndices.push_back(4); cubeIndices.push_back(5); cubeIndices.push_back(6); cubeIndices.push_back(4); cubeIndices.push_back(6); cubeIndices.push_back(7); // back cubeVertices.push_back(Vector3( d,-d,-d)); cubeVertices.push_back(Vector3(-d,-d,-d)); cubeVertices.push_back(Vector3(-d, d,-d)); cubeVertices.push_back(Vector3( d, d,-d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(0,0,-1)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.3,0.3,0.8)); cubeIndices.push_back(8); cubeIndices.push_back(9); cubeIndices.push_back(10); cubeIndices.push_back(8); cubeIndices.push_back(10); cubeIndices.push_back(11); // left cubeVertices.push_back(Vector3(-d,-d, d)); cubeVertices.push_back(Vector3(-d,-d,-d)); cubeVertices.push_back(Vector3(-d, d,-d)); cubeVertices.push_back(Vector3(-d, d, d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(-1,0,0)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.8,0.8,0.3)); cubeIndices.push_back(12); cubeIndices.push_back(13); cubeIndices.push_back(14); cubeIndices.push_back(12); cubeIndices.push_back(14); cubeIndices.push_back(15); // top cubeVertices.push_back(Vector3(-d, d,-d)); cubeVertices.push_back(Vector3( d, d,-d)); cubeVertices.push_back(Vector3( d, d, d)); cubeVertices.push_back(Vector3(-d, d, d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(0,1,0)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.8,0.3,0.8)); cubeIndices.push_back(16); cubeIndices.push_back(17); cubeIndices.push_back(18); cubeIndices.push_back(16); cubeIndices.push_back(18); cubeIndices.push_back(19); // bottom cubeVertices.push_back(Vector3( d,-d,-d)); cubeVertices.push_back(Vector3(-d,-d,-d)); cubeVertices.push_back(Vector3(-d,-d, d)); cubeVertices.push_back(Vector3( d,-d, d)); for(int k = 0; k &lt; 4; k++) cubeNormals.push_back(Vector3(0,-1,0)); for(int k = 0; k &lt; 4; k++) cubeColors.push_back(Vector3(0.3,0.8,0.8)); cubeIndices.push_back(20); cubeIndices.push_back(21); cubeIndices.push_back(22); cubeIndices.push_back(20); cubeIndices.push_back(22); cubeIndices.push_back(23); cube-&gt;setIndices(cubeIndices, mat); //we set the cubeIndices and the material for the cube cube-&gt;setVertexPositions(cubeVertices); cube-&gt;setVertexNormals(cubeNormals); cube-&gt;setVertexColors(cubeColors); return cube; } </code></pre> <p>and then we iterate through all of our cubes in the draw scene method in order to draw them</p> <pre><code>for (std::vector&lt;Mesh3D*&gt;::iterator mIt = m_meshes.begin(); mIt != m_meshes.end(); ++mIt) { Mesh3D* cube = *mIt; m_meshShaderTexture.setMatrix4x4Uniform("modelworld", cube-&gt;getTransformation()); cube-&gt;getMaterial(0).m_diffuseTexture.bind(); m_meshShaderTexture.setIntUniform("texture", cube-&gt;getMaterial(0).m_diffuseTexture.getLayer()); draw_object(m_meshShaderTexture, cube);// method called to draw the cube } </code></pre> <p>We called this line in the method "drawObject" which has for purpose to draw the mesh3d objects : </p> <pre><code> void SolarViewer::draw_object(Shader&amp; sh, Mesh3D *mesh) { sh.setMatrix4x4Uniform("modelworld", mesh-&gt;getTransformation() ); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer( 3, GL_DOUBLE, 0, mesh-&gt;getVertexPointer() ); glNormalPointer( GL_DOUBLE, 0, mesh-&gt;getNormalPointer() ); glTexCoordPointer( 2, GL_DOUBLE, 0, mesh-&gt;getUvTextureCoordPointer() ); for(unsigned int i = 0; i &lt; mesh-&gt;getNumberOfParts(); i++) { glDrawElements( GL_TRIANGLES, mesh-&gt;getNumberOfFaces()*3, GL_UNSIGNED_INT, mesh-&gt;getVertexIndicesPointer() ); } glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } </code></pre> <p>But at the end, while trying to compile, the following line gives us a BAD_ACCESS :(</p> <pre><code>glDrawElements( GL_TRIANGLES, mesh-&gt;getNumberOfFaces()*3, GL_UNSIGNED_INT, mesh-&gt;getVertexIndicesPointer() ); </code></pre> <p>What are we doing wrong ? Is it enough to bind the following texture (.tga) to have the glowing effect ? : <a href="http://i166.photobucket.com/albums/u83/j1m68/star.jpg" rel="nofollow">http://i166.photobucket.com/albums/u83/j1m68/star.jpg</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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