Esempio n. 1
0
VertexDef boot_vert_def()
{
    boot_vert* proxy = 0;
    VertexDef VD = CreateVertexDef(sizeof(boot_vert), 2);
    int i = 0;
    AddVertexAttribute(VD, i++, VERTEX_POSITION_ATTR, (size_t)&proxy->location, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_UV_ATTR, (size_t)&proxy->uv, 2, GL_FLOAT);

    return VD;
}
Esempio n. 2
0
VertexDef boot_vert_def()
{
    boot_vert* proxy = 0;
    VertexDef VD = CreateVertexDef(sizeof(boot_vert), 3);
    int i = 0;
    AddVertexAttribute(VD, i++, VERTEX_POSITION_ATTR, (size_t)&proxy->location, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_NORMAL_ATTR, (size_t)&proxy->normal, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_COLOR_ATTR, (size_t)&proxy->color, 4, GL_FLOAT);

    return VD;
}
VertexDef editor_vert_def()
{
    editor_vert* proxy = 0;
    VertexDef VD = CreateVertexDef(sizeof(editor_vert), 1);
    int i = 0;
    AddVertexAttribute(VD, i++, VERTEX_POSITION_ATTR, (size_t)&proxy->location, 3, GL_FLOAT);

    return VD;
}
Esempio n. 4
0
tVertexDescription::tVertexDescription( const tMesh& mesh )
{
    int offsetInBytes = 0;
    int strideInBytes = 0;

    // Position attribute
    tVertexAttribute attribute = mesh.AttributeCopy(tVertexAttribute::eVAT_Position);
    
    if( attribute.Type() != tVertexAttribute::eVAT_Null )
    {
        offsetInBytes += AddVertexAttribute(attribute, offsetInBytes, strideInBytes);
    }

    // Color attribute
    attribute = mesh.AttributeCopy(tVertexAttribute::eVAT_Color);

    if( attribute.Type() != tVertexAttribute::eVAT_Null )
    {
        offsetInBytes += AddVertexAttribute(attribute, offsetInBytes, strideInBytes);
    }

    // Normal attribute
    attribute = mesh.AttributeCopy(tVertexAttribute::eVAT_Normal);

    if( attribute.Type() != tVertexAttribute::eVAT_Null )
    {
        offsetInBytes += AddVertexAttribute(attribute, offsetInBytes, strideInBytes);
    }

    // TexCoord attributes
    int numberOfTexCoordAttributes = mesh.NumberOfTextureStages();

    for(int i = 0; i < numberOfTexCoordAttributes; ++i)
    {
        attribute = mesh.AttributeCopy(tVertexAttribute::eVAT_TextureCoord, i);

        if( attribute.Type() != tVertexAttribute::eVAT_Null )
        {
            offsetInBytes += AddVertexAttribute(attribute, offsetInBytes, strideInBytes);
        }
    }
}
Esempio n. 5
0
// Depricated.
VertexDef obj_vert_def_depr()
{
    obj_vert* proxy = 0;
    VertexDef VD = CreateVertexDef(sizeof(obj_vert), 7);
    int i = 0;
    AddVertexAttribute(VD, i++, VERTEX_POSITION_ATTR, (size_t)&proxy->location, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_NORMAL_ATTR, (size_t)&proxy->normal, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_UV_ATTR, (size_t)&proxy->uv, 2, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_COLOR_ATTR, (size_t)&proxy->diffuse, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR_0, (size_t)&proxy->ambient, 3, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR_1, (size_t)&proxy->specular, 4, GL_FLOAT);
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR_2, (size_t)&proxy->emissive, 4, GL_FLOAT);

    return VD;
}
Esempio n. 6
0
VertexDef obj_vert_def()
{
    obj_vert* proxy = 0;
    VertexDef VD = CreateVertexDef(sizeof(obj_vert), 7);
    int i = 0;
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->location, 3, GL_FLOAT, "in_vertex");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->normal, 3, GL_FLOAT, "in_normal");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->uv, 2, GL_FLOAT, "in_uv");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->diffuse, 3, GL_FLOAT, "in_color");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->ambient, 3, GL_FLOAT, "in_ambient");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->specular, 4, GL_FLOAT, "in_specular");
    AddVertexAttribute(VD, i++, VERTEX_OTHER_ATTR, (size_t)&proxy->emissive, 4, GL_FLOAT, "in_emissive");

    return VD;
}
Esempio n. 7
0
static void ReadOBJ(const char *filename) {
    FILE *fp = fopen(filename, "r");
     if (fp == NULL)
         sreFatalError("Could not open file %s.", filename);
    for (;;) {
        char *str = GetWords(fp);
        if (str == NULL)
            // End of file.
            break;
        RemoveComments();
        if (nu_words == 0)
            continue;
        int command = - 1;
        if (strcmp(words[0], "v") == 0)
           command = 0;
        else if (strcmp(words[0], "vn") == 0)
           command = 1;
        else if (strcmp(words[0], "vt") == 0)
           command = 2;
        else if (strcmp(words[0], "f") == 0)
           command = 3;
        if (command < 0)
            // First word not recognized.
            continue;
        if (command <= 2) {
           // Get up to four coordinates.
           float coord[4];
           int n = GetCoordinates(1, coord);
           if (command == 0)
               AddVertexAttribute(SRE_ATTRIBUTE_POSITION, coord, n);
           else if (command == 1)
               AddVertexAttribute(SRE_ATTRIBUTE_NORMAL, coord, n);
           else
               AddVertexAttribute(SRE_ATTRIBUTE_TEXCOORDS, coord, n);
        }
        else {
            // Face defition.
            BeginFace(4, SRE_POSITION_MASK | SRE_NORMAL_MASK | SRE_TEXCOORDS_MASK);
            for (int word_index = 1; word_index < nu_words; word_index++) {
                int vertex_index[3];
                DecodeOBJFaceIndices(words[word_index], vertex_index);
                for (int k = 0; k < 3; k++) {
                    // Special value INT_MAX means not used; AddFace expects - 1
                    // for unused attributes.
                    if (vertex_index[k] == INT_MAX)
                        vertex_index[k] = - 1;
                     else {
                        if (vertex_index[k] > 0)
                            // Regular index; counting starts at 1 in OBJ files.
                            vertex_index[k]--;
                        else if (vertex_index[k] < 0)
                            // Negative numer is relative index.
                            vertex_index[k] += nu_attribute_vertices[OBJ_attributes[k]];
                        else
                            ModelFileReadError("Vertex index of 0 not allowed in OBJ file");
                    }
                }
                AddFaceVertex(OBJ_attributes, vertex_index);
            }
            EndFace();
        }
    }
    fclose(fp);
}