Home Up Feedback Contents Search

Mobius Brick Shader
Mobius Brick Shader Texture and Mandelbrot OpenGL EC-SC driver Component Object Model Custom Visual Testing

 

[Under Construction]

Home
Up

 

 

Mobius strip is created as a vertex buffer object, then rendered within a torus. OpenGL 1.5

    This code copyright John B Coke.  All rights reserved.

    Besides if you really understand the concepts you don't need to copy this.

    for (int i = 0; i <= 3600; i++)

        {

            theta = i * radiansPerDegree / 10;

            float p,q,r;

            int j = i/10;

            p = (j*7%255)/255.0;

            q = ((((j+4)*11)+56)%255)/255.0;

            r = (((j+23)*41)%255)/255.0;

            float X1,Y1,Z1,X2,Y2,Z2;

            float a[3],b[3],c[3];

            glColor4f(p,q,r,0.2);

                x1 = length*cos(theta/2);  // i/2 rotation per orbit

                y1 = length*sin(theta/2);

                z1 = 0;

                x2 = cos(theta)*x1;

                z2 = sin(theta)*x1;

                X1 = m_vertices[2*i][0] = cos(theta)*radius + x2;

                Y1 = m_vertices[2*i][1] = y1;

                Z1 = m_vertices[2*i][2] = sin(theta)*radius + z2;

                X2 = m_vertices[2*i+1][0] = cos(theta)*radius-x2;

                Y2 = m_vertices[2*i+1][1] = -y1;

                Z2 = m_vertices[2*i+1][2] = sin(theta)*radius - z2;

                a[0] = X2-X1;

                a[1] = Y2-Y1;

                a[2] = Z2-Z1;

                b[0] = sin(theta);

                b[1] = 0;

                b[0] = cos(theta);

                lib3ds_vector_cross(c,a,b);

                lib3ds_vector_normalize(c);

                m_normals[2*i][0] = c[0];

                m_normals[2*i][1] = c[1];

                m_normals[2*i][2] = c[2];

                m_normals[2*i+1][0] = c[0];

                m_normals[2*i+1][1] = c[1];

                m_normals[2*i+1][2] = c[2];

                m_colors[2*i][0] = p;

                m_colors[2*i][1] = q;

                m_colors[2*i][2] = r;

                m_colors[2*i][3] = 0.2;

                m_colors[2*i+1][0] = p;

                m_colors[2*i+1][1] = q;

                m_colors[2*i+1][2] = r;

                m_colors[2*i+1][3] = 0.2;

                m_texcoords[2*i][0] = -1;

                m_texcoords[2*i][1] = (4.0/1800.0)*(i%1000) -1 ;

                m_texcoords[2*i+1][0] = 1;

                m_texcoords[2*i+1][1] = (4.0/1800.0)*(i%1000) -1  ;

 

        }

 

        m_polygons[0] = numFaces;

        // first the vertices

        glBindBuffer(GL_ARRAY_BUFFER,buffers[0]);

        // first vbo 2 vertices per face, 3 coords per vertex and 4 bytes per float

        glBufferData(GL_ARRAY_BUFFER, numFaces*2*3*4, &m_vertices, GL_STATIC_DRAW);

        // then the colors

        glBindBuffer(GL_ARRAY_BUFFER,buffers[1]);

        // second vbo 2 vertices per faces, 4 coords per color, 4 bytes per float

        glBufferData(GL_ARRAY_BUFFER, numFaces*2*4*4, &m_colors, GL_STATIC_DRAW);

        // then some texture coorddinates

        glBindBuffer(GL_ARRAY_BUFFER,buffers[2]);

        // third vbo 2 vertices per face 2 coords per vertex and 4 bytes per float

        glBufferData(GL_ARRAY_BUFFER, numFaces*2*2*4, &m_texcoords, GL_STATIC_DRAW);

        // perhaps some normals

        glBindBuffer(GL_ARRAY_BUFFER,buffers[3]);

        // first vbo 2 vertices per face, 3 coords per vertex and 4 bytes per float

        glBufferData(GL_ARRAY_BUFFER, numFaces*2*3*4, &m_normals, GL_STATIC_DRAW);

 

2)  The fragments are being shaded along a mobius strip, within the torus. OpenGL 2.0.

On the left is the common brick shader with x,y as parameters

and then with tex coords as parameters on the right

 

Home ] Up ]

Send mail to john@cosoftech.com with questions or comments about this web site.
Last modified: 07/27/09