Beispiel #1
0
VertexAttribute::VertexAttribute(string name, int nComponents, int componentsType)
{
    bool correct = true;
    if(componentsType == GL_FLOAT) componentsSize = 4;
    else if(componentsType == GL_SHORT) componentsSize = 1;
    else
    {
        DbgError("Not recognized vertex attribute type!");
        correct = false;
        componentsSize = 0;
    }

    if(correct)
    {
        if(nComponents > 4 or nComponents < 0)
        {
            componentsSize = 0;
            DbgError("A vertex attribute can have more than 4 elements or less than 0.");
        }
        else
        {
            this->name = name;
            this->componentsNum = nComponents;
            this->componentsType = componentsType;
        }
    }
}
Beispiel #2
0
bool Image::Save(cchar *szFile)
{
  if (!szFile)
  {
    DbgError("Null file name!");
    return false;
  }

  DbgMessage("Image %s", szFile);

  FILE *pFile = fopen(szFile, "wb");
  if (!pFile)
  {
    DbgError("Unable to open file %s for writing!", szFile);
    return false;
  }

  bool success = Save(pFile);
  fclose(pFile);
  return success;
}
Beispiel #3
0
unsigned char* Image::LoadFromFile(const char *filepath)
{
    int n;
    data = stbi_load(filepath, &width, &height, &n, 0);
    if(data == 0)
    {
        width = height = format = size = 0;
        DbgError("Error loading the texture '" << filepath << "', couldn't open/read the file.");
        return data;
    }
    if(n == 3) format = GL_RGB;
    else format = GL_RGBA;

    size = width * height * n * sizeof(float);

    return data;
}