Thread: OpenGL

  1. #1
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Post OpenGL

    Anyone familiar with opengl ?

    OpenGL-balls-png

    I am able to read the vertices and indices in from the file (in the picture you can see the white spheres) and draw using glDrawElements. When i import the data from an object and plug in the arrays the object has connected points that shouldn't be (blue background and red spheres are opengl output). The extra connected points are also flickering.
    Last edited by Structure; 09-04-2019 at 08:51 AM.
    "without goto we would be wtf'd"

  2. #2
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    OpenGL-cone-png
    Last edited by Structure; 09-04-2019 at 08:58 AM.
    "without goto we would be wtf'd"

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You're obviously doing something wrong at either the loading or the rendering phase. Without code, we can just guess.
    Devoted my life to programming...

  4. #4
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Post

    either the loading or the rendering phase
    both, i solved the rendering phase problem.

    OpenGL-nolines-png

    I was passing the wrong type of value to glDrawElements().

    As far as the loading phase goes I'm still converting .obj files faces to all triangles and hopefully that solves the problem with the cone.

    OpenGL-outcone-png

    All the flickering is gone and most of the triangles are drawn now. But if you take a look from the inside of the cone...

    OpenGL-incone-png

    I believe this is an issue with the loading phase because i have not solved all the triangles from the faces when the faces have more than 4 vertices.
    Last edited by Structure; 09-05-2019 at 03:07 PM.
    "without goto we would be wtf'd"

  5. #5
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Cool

    OpenGL-cone10-png
    "without goto we would be wtf'd"

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    OpenGL-cone10-png

  7. #7
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    The extra triangles appear before i triangulated the polygons. Not sure why ... ?
    "without goto we would be wtf'd"

  8. #8
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    Code:
    void tris_indiced(float mesh[],int meshSize,unsigned int indices[],int indiceSize) {
      glBufferData(GL_ARRAY_BUFFER, meshSize, mesh, GL_DYNAMIC_DRAW);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, indiceSize, indices, GL_DYNAMIC_DRAW);
      glDrawElements(GL_TRIANGLES, indiceSize/sizeof(indices[0]), GL_UNSIGNED_INT, NULL );
    };
    Code:
    render() {
      glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
      tris_indiced(sphere_vertices,sizeof(sphere_vertices),sphere_indices,sizeof(sphere_indices) );
    };
    "without goto we would be wtf'd"

  9. #9
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Question

    vertex.glsl
    Code:
    layout (location = 0) in vec3 position;
    layout (location = 1) in vec2 inCoords;
    layout (location = 2) in vec4 fragmentColor;
    
    out vec2 TexCoords;
    out vec4 fragColor;
    out vec4 setColor;
    
    out vec3 pCoords;
    
    uniform mat4 scale;
    uniform mat4 rotateX;
    uniform mat4 rotateY;
    uniform mat4 rotateZ;
    uniform mat4 translation;
    
    uniform vec4 inColor;
    
    mat4 project(float fov, float aspect, float zNear, float zFar) {
        mat4 proj_mat;
        float fovRad = 1/tan(radians(fov)/2);
        proj_mat[0] = vec4( aspect * fovRad, 0.0, 0.0, 0.0 );
        proj_mat[1] = vec4( 0.0, fovRad, 0.0, 0.0 );
        proj_mat[2] = vec4( 0.0, 0.0, zFar / (zFar - zNear), 1.0 );
        proj_mat[3] = vec4( 0.0, 0.0, (-zFar * zNear) / (zFar - zNear), 0.0 );
        return proj_mat;
    }
    
    void main() {    
        float wx = 1.0; 
        mat4 rotation = (rotateX * rotateY * rotateZ);
        vec4 rawPOS = vec4(position.xyz,wx);
        mat4 view = (rotation * translation * scale);
        mat4 projection = project( 45, 800/600, 0.1, 10000);
        
        TexCoords = inCoords; 
        fragColor = fragmentColor; 
        setColor = inColor; 
        pCoords = position;
    
        gl_Position = (projection * view * rawPOS);   
    }
    fragment.glsl
    Code:
    precision mediump float; 
    
    out vec4 color;
    
    in vec4 fragColor;
    in vec4 setColor;
    
    in vec3 pCoords;
    
    in vec2 TexCoords;
    uniform sampler2D thisTexture;
    
    void main(){   
        if (setColor.w > 0) {
             color = setColor;
        } else {
            color = texture(thisTexture, TexCoords) * setColor;
        }; 
    }
    One thing i am doing that is different is instead of subtracting 1 from the array, i inserted a 0,0,0 at the top of the indices. Would this cause extra triangles ?
    Last edited by Structure; 09-16-2019 at 08:30 AM.
    "without goto we would be wtf'd"

  10. #10
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    One minor thing: You shouldn't do the matrix-to-matrix multiplications inside the shader, unless you have direct use for those matrices. The CPU is far better suited for that task. I usually just pass the projection and transformation matrices to the vertex shader. If you're doing this because you have no 3D math libraries, GLM comes to mind.
    Devoted my life to programming...

  11. #11
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    If you're doing this because you have no 3D math libraries
    I'm working on a matrix library. That is exactly why.
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2010, 01:26 PM
  2. OpenGL Quesiton: Does Windows XP, Vista still at OpenGL 1.1?
    By indigo0086 in forum Game Programming
    Replies: 8
    Last Post: 05-21-2007, 11:18 AM
  3. new to opengl
    By Darkinyuasha1 in forum Game Programming
    Replies: 8
    Last Post: 11-06-2006, 06:13 PM
  4. Replies: 5
    Last Post: 02-12-2006, 08:42 PM
  5. OpenGL, texturing...and...more OpenGL
    By Sunny in forum Game Programming
    Replies: 2
    Last Post: 07-08-2002, 02:34 PM

Tags for this Thread