int main(void)
{
   Type **ppObj;
   int rows, cols, gotFailure = 0;

   for (
      rows = ROW_COUNT_START, cols = COL_COUNT_START;
      rows < DIM_MAX && cols > 0;
      rows += DIM_STEP, cols -= DIM_STEP
       )
   {
      int failed;
      /* Create a 2D array of "Objects" dynamically. */
      ppObj = Create2D((size_t)rows, (size_t)cols);
      /* Test it and print the results. */
      failed = Test2D(ppObj, rows, cols);
      /* Free the array. */
      Free2D((void *)ppObj);
      if (failed)
      {
         gotFailure = 1;
         fprintf(stderr, "Create2D(%d, %d) failed\n", rows, cols);
      }
      else
         printf("Create2D(%d, %d) succeeded\n", rows, cols);
   }
   if (gotFailure)
      return EXIT_FAILURE;
   return EXIT_SUCCESS;
}
Beispiel #2
0
Texture*
Texture::LoadCubeMap(
    const Symbol& name,
    vd::string filenames[6])
{
    ImageFormat format;
    ImageBuffer8u pixels;
    ImageInput& input = ImageInput::GetInstance();

    if(input.Open(filenames[0], format) != Status::Code::Success)
    {
        vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filenames[0].c_str());
        return false;
    }

    if(input.Read(pixels) != Status::Code::Success)
    {
        vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filenames[0].c_str());
        return false;
    }

    GLenum internal = GL_RGBA;
    GLenum layout = GL_RGBA;
    switch(format.Channels.Count)
    {
    case 1:
        internal = layout = GL_LUMINANCE;
        break;
    case 2:
        internal = layout = GL_LUMINANCE_ALPHA;
        break;
    case 3:
        internal = layout = GL_RGB;
        break;
    case 4:
        internal = layout = GL_RGBA;
        break;
    default:
        vdLogGlobalWarning("Invalid channel layout for creating texture from image file '%s'\n", filenames[0].c_str());
        return NULL;
    };

    Texture::Properties properties;
    properties.Reset();
    properties.Name = name;
    properties.Handle = 0;
    properties.Width = format.Width;
    properties.Height = format.Height;
    properties.Target = GL_TEXTURE_2D;
    properties.Internal = internal;
    properties.Format = layout;
    properties.DataType = GL_UNSIGNED_BYTE;
    properties.WrapMode = GL_MIRRORED_REPEAT;
    properties.MagFilterMode = GL_LINEAR;
    properties.MinFilterMode = GL_LINEAR_MIPMAP_LINEAR;
    properties.UseMipMaps = true;

    Texture* cubemap = Create2D(properties, NULL);
    if(!cubemap)
    {
        vdLogGlobalWarning("Error: Failed to allocate memory for cube map '%s'\n", filenames[0].c_str());
        return cubemap;
    }
    const GLenum aeCubeFaces[] =
    {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
    };

    vd::u8* rgba = (vd::u8*)pixels.Data;
    for(GLuint i = 0; i < 6; i++)
    {
        if(i > 0)
        {
            if(input.Open(filenames[i], format) != Status::Code::Success)
            {
                vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filenames[i].c_str());
                return false;
            }

            if(input.Read(pixels) != Status::Code::Success)
            {
                vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filenames[i].c_str());
                return false;
            }
            rgba = (vd::u8*)pixels.Data;
        }

        glTexImage2D(aeCubeFaces[i], 0, properties.Internal, properties.Width, properties.Height,
                     0, properties.Format, properties.DataType, rgba);
        Texture::CheckStatus(name, "Allocating cubemap face texture");
    }

    input.Close();

    return cubemap;
}
Beispiel #3
0
ConfigData::ConfigData(int len1, int len2, int len3, int len4, int md, bool vb=true){
	leng1=len1; leng2=len2; leng3=len3; leng4=len4; matrixdim=md;
	nsite=leng1*leng2*leng3*leng4;

	verbose=vb;

	A = new CArray(nsite, DIM, matrixdim, matrixdim);

	neibArray = Create2D(nsite, DIM*2);

	// Fills the neib array
        int i1p,i2p,i3p,i4p,i1m,i2m,i3m,i4m,is,isp1,isp2,isp3,isp4,ism1,ism2,ism3,ism4;
        for(int i1 = 0;i1<leng1;i1++){
                i1p = i1 + 1;
                i1m = i1 - 1;
                if (i1p == leng1) i1p = 0;
                if (i1m == -1) i1m = leng1-1;

                for(int i2 = 0;i2<leng2;i2++){
                        i2p = i2 + 1;
                        i2m = i2 - 1;
                        if (i2p == leng2) i2p = 0;
                        if (i2m == -1) i2m = leng2-1;

                        for(int i3 = 0;i3<leng3;i3++){
                                i3p = i3 + 1;
                                i3m = i3 - 1;
                                if (i3p == leng3) i3p = 0;
                                if (i3m == -1) i3m = leng3-1;

                                for(int i4 = 0;i4<leng4;i4++){
                                        i4p = i4 + 1;
                                        i4m = i4 - 1;
                                        if (i4p == leng4) i4p = 0;
                                        if (i4m == -1) i4m = leng4-1;

                                        // Compute the site address and the addresses of the sites shifted
                                        // by one unit in each direction

                                        is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;

                                        isp1 = i1p + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
                                        isp2 = i1 + i2p*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
                                        isp3 = i1 + i2*leng1 + i3p*leng1*leng2 + i4*leng1*leng2*leng3;
                                        isp4 = i1 + i2*leng1 + i3*leng1*leng2 + i4p*leng1*leng2*leng3;

                                        ism1 = i1m + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
                                        ism2 = i1 + i2m*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
                                        ism3 = i1 + i2*leng1 + i3m*leng1*leng2 + i4*leng1*leng2*leng3;
                                        ism4 = i1 + i2*leng1 + i3*leng1*leng2 + i4m*leng1*leng2*leng3;

                                        // Fill the neib array

                                        neibArray[is][0] = isp1;
                                        neibArray[is][1] = isp2;
                                        neibArray[is][2] = isp3;
                                        neibArray[is][3] = isp4;

                                        neibArray[is][4] = ism1;
                                        neibArray[is][5] = ism2;
                                        neibArray[is][6] = ism3;
                                        neibArray[is][7] = ism4;
                                }
                        }
                }
	}
}