سؤال

Currently i am working in simple game app using openGLES, draw a line using GL_Lines mode and working fine, i want to draw a line using GL_TRIANGLE_STRIP, is it possible to draw a line using GL_TRIANGLE_STRIP?

Thanks in Advance

I tried the source code:

  glClearColor(0.65f, 0.65f, 0.65f, 1.0f); //Background color changes, its like Red,Green,Blue,Alpha color. 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    [self.effect prepareToDraw];


        const GLfloat line[] = 
        {
            0.0f, 0.5f,
            0.0f, -1.5f,
           0.0f,-1.5f,
        };

        // Create buffer object array
        GLuint bufferObjectNameArray;

        // Have OpenGL generate a buffer name and store the buffer object array 
        glGenBuffers(1, &bufferObjectNameArray);

        // Bind the buffer object array to the GL_ARRAY_BUFFER target buffer  
        glBindBuffer(GL_ARRAY_BUFFER, bufferObjectNameArray); 

        // Send the line data over to the target buffer
        glBufferData(
                     GL_ARRAY_BUFFER,   // the target buffer 
                     sizeof(line),      // the number of bytes to put into the buffer
                     line,              // a pointer to the data being copied 
                     GL_STATIC_DRAW);   // the usage pattern of the data 

        // Enable vertex data to be fed down the graphics pipeline to be drawn
        glEnableVertexAttribArray(GLKVertexAttribPosition); 

        // Specify how the GPU looks up the data 
        glVertexAttribPointer(
                              GLKVertexAttribPosition, // the currently bound buffer holds the data 
                              2,                       // number of coordinates per vertex 
                              GL_FLOAT,                // the data type of each component 
                              GL_FALSE,                // can the data be scaled 
                              2*4,                    // how many bytes per vertex (2 floats per vertex)
                              NULL);                   // offset to the first coordinate, in this case 0 
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); 
هل كانت مفيدة؟

المحلول

You need to duplicate each vertex of the line and offset it:

const GLfloat line[] = 
    {
        -1.0f, 0.5f, 1.0f, 0.5f,//0.0f, 0.5f,
        -1.0f, 0.5f, 1.0f, 1.5f,//0.0f, -1.5f,
    };
...
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

It's simply for line with predefined line direction. Otherwise you need to calculate direction of offset as perpendicular to direction of line.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top