Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: vertex data

  1. #1
    Intern Contributor
    Join Date
    Feb 2013
    Posts
    75

    vertex data

    Hello forum ,

    Is it mandatory to have the vertex data of a mesh within [0,1] to render it. I have pulled out vertex data that has the following format:

    Code :
    float TeapotPositions[289][3] = {
    	{ -99.2795f, -3.6791f, 439.434f },
    	{ -84.694f, 14.2227f, 477.825f },
    	{ -39.9517f, 23.4452f, 497.602f },
    	{ 2.40749f, 17.2811f, 484.383f },
    	{ -99.2795f, -19.9926f, 447.041f },
    	{ -84.694f, -2.09085f, 485.432f },
    	{ -39.9517f, 7.13163f, 505.209f },
    	{ 2.40749f, 0.967554f, 491.991f },
    	{ -80.3691f, -30.9012f, 444.944f },
    	{ -69.43f, -17.4749f, 473.736f },
    	{ -35.8733f, -10.558f, 488.57f },
    	{ -4.10388f, -15.1811f, 478.656f },
    	{ -80.3691f, -33.6202f, 446.211f },
    	{ -69.43f, -20.1938f, 475.004f },
    	{ -35.8733f, -13.2769f, 489.838f },
    	{ -4.10388f, -17.9f, 479.923f },
    	{ 44.7667f, 11.117f, 471.165f },
    	{ 66.589f, -7.79188f, 430.614f },
    	{ 52.0035f, -25.6937f, 392.224f },
    	{ 44.7667f, -5.19653f, 478.772f },
    	{ 66.589f, -24.1054f, 438.221f },
    	{ 52.0035f, -42.0072f, 399.831f },
    	{ 27.6655f, -19.8041f, 468.741f },
    	{ 44.0322f, -33.9858f, 438.329f },
    	{ 33.0932f, -47.4122f, 409.536f },
    	{ 27.6655f, -22.5231f, 470.009f },
    	{ 44.0322f, -36.7047f, 439.597f },
    	{ 33.0932f, -50.1311f, 410.804f },
    	{ -80.3691f, 47.9476f, 408.176f },
    	{ -69.43f, 61.3739f, 436.969f },
    	{ -35.8733f, 68.2908f, 451.802f },
    	{ -4.10388f, 63.6677f, 441.888f },
    	{ -89.8243f, 30.291f, 420.001f },
    ..............................
    ..............................

    When i try to render it i am getting a blank screen with the following snippet:


    Code :
     
    void startup()
    {
        //define the inner and outer
        //tessellation level
        inner = 1;
        outer = 1;
     
        const GLsizei vec3Stride = 3 * sizeof(GLdouble);
        const GLsizei indexStride = sizeof(GLint);
        vertCount = sizeof(TeapotPositions)/vec3Stride;
        knotCount = sizeof(TeapotKnots)/indexStride;
     
        glGenVertexArrays(1,&vaoID);
        glBindVertexArray(vaoID);
     
        //now generat the buffer IDs
        glGenBuffers(NumVertexBuffers,buffersID);
     
    //    GLsizei totalSize = vec3Stride * vertCount;
        //create the vbo for positions
        glBindBuffer(GL_ARRAY_BUFFER,buffersID[ArrayBuffer]);
        glBufferData(GL_ARRAY_BUFFER,sizeof(TeapotPositions),TeapotPositions,GL_STATIC_DRAW);
     
        //creat the knot vbo
    //    totalSize = indexStride * knotCount;
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buffersID[ElementBuffer]);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(TeapotKnots),TeapotKnots,GL_STATIC_DRAW);
     
        //load the shader
        loadShaders();
     
        glVertexAttribPointer((*teapotTessellationShader)["vPosition"], //index of the attribute inside the shader
                              3,                                        //number of components per generic vertex attribute
                              GL_FLOAT,                                //specifies the data type
                              GL_FALSE,                                 //the data is not normalized
                              0,                                        //vertex attributes are tightly packed
                              BUFFER_OFFSET(0));                        //specifies the first component of the first generic vertex attributes.
        glEnableVertexAttribArray((*teapotTessellationShader)["vPosition"]);
     
        glClearColor(0.0,0.0,0.0,1.0);
     
        //i got some interesting artifacts if i do not set the
        //following function with the parameter
        glPatchParameteri(GL_PATCH_VERTICES,16);
     
        glfwGetFramebufferSize(window,&winWidth,&winHeight);
     
        ProjectionMatrix = glm::perspective(60.0f,(GLfloat)winWidth/winHeight,0.01f,100.0f);
     
        glViewport(0,0,winWidth,winHeight);
     
     
        //get the maximum patch vertices that this driver supports
        glGetIntegerv(GL_MAX_PATCH_VERTICES,&maxPatchVertices);
     
        glEnable(GL_DEPTH_TEST);
    }
     
    ........................
     
    ........................
     
    void render(float currentTime)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        //set the modelview matrix and send it to the shader along with the projection matrix
        glm::mat4 trans1 = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,0.0f,-zoom));
        glm::mat4 rotY = glm::rotate(glm::mat4(1.0f),currentTime,glm::vec3(0.0f,1.0f,0.0f));
        glm::mat4 rotX = glm::rotate(glm::mat4(1.0f),180.0f,glm::vec3(1.0f,0.0f,0.0f));
        glm::mat4 scale1 = glm::scale(glm::mat4(1.0f),glm::vec3(0.01));
     
        ModelviewMatrix = trans1 * rotY; //* scale1;// * rotX;
     
        teapotTessellationShader->Use();
     
        glUniformMatrix4fv((*teapotTessellationShader)("ModelviewMatrix"),1,GL_FALSE,glm::value_ptr(ModelviewMatrix));
     
        glUniformMatrix4fv((*teapotTessellationShader)("ProjectionMatrix"),1,GL_FALSE,glm::value_ptr(ProjectionMatrix));
     
        glUniform1f((*teapotTessellationShader)("inner"),inner);
        glUniform1f((*teapotTessellationShader)("outer"),outer);
     
        glPolygonMode(GL_FRONT_AND_BACK,renderingMode);
     
        glDrawElements(GL_PATCHES,vertCount,GL_UNSIGNED_INT,BUFFER_OFFSET(0));
     
     
        teapotTessellationShader->UnUse();
    }


    Any hint ?


    Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    No, a mesh can have (within reason) arbitrary coordinates. Only after transformation to clip space and perspective division does it have to fit into [-1,1]^3, so it is the job of your modelview and projection matrices to transform the "right" part of your world to fit into that cube.

    Your camera has a far value of 100, but the vertices have z coordinates around 400. If your camera is near the origin the model is likely past the far clipping plane and also possibly behind you (depends on your rotation values), because by default the camera would look along the negative z axis and thus only negative z values would be in view.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •