Exemplo n.º 1
0
void Menu::DisplayError(const std::string & msg)
{
  play_error_sound();

  std::cerr << msg << std::endl;

  Question question(Question::WARNING);
  question.Set(msg, true, 0);
  question.Ask();
}
Exemplo n.º 2
0
Arquivo: hw1.c Projeto: MaikuMori/gfx
static GLboolean load_image(char * filename)
{
    GLint x,y,n;

    if (image_data != NULL)
    {
        stbi_image_free(image_data);
    }

    image_data = stbi_load(filename, &x, &y, &n, 4);

    if (image_data == NULL) {
        play_error_sound();
        printf("Error: Failed to open image: %s.\n", filename);
        return GL_FALSE;
    }

    if (x != TEXTURE_WIDTH || y !=TEXTURE_HEIGHT)
    {
        play_error_sound();
        printf("Error: Image should be %dpx x %dpx. Scaling isn't currently supported.\n", TEXTURE_WIDTH, TEXTURE_HEIGHT);
        return GL_FALSE;
    }

    glBindTexture(GL_TEXTURE_2D, textures[1]);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    //Just in case even though not using mipmaps.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

    glTexImage2D(GL_TEXTURE_2D, 0, n, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) image_data);

    return GL_TRUE;
}
Exemplo n.º 3
0
Arquivo: hw1.c Projeto: MaikuMori/gfx
static void open_file(void)
{
    OPENFILENAME ofn;
    TCHAR szFile[MAX_PATH];
    TCHAR cur_dir[FILENAME_MAX];

    size_t file_len;
    size_t converted_len = 0;
    char converted_filename[MAX_PATH];

    opening_file = GL_TRUE;

    szFile[0] = '\0';
    szFile[1] = '\0';

    //Get current working directory.
    GetCurrentDirectory(sizeof(TCHAR) * FILENAME_MAX, cur_dir);

    //Initialize OPENFILENAME
    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    ofn.lpstrFile = szFile;
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFilter = TEXT("Images (*.jpg;*.png;*.bmp;*.tga;*.psd)\0*.jpg;*.png;*.bmp;*.tga;*.psd\0");
    ofn.lpstrInitialDir = TEXT("Images");
    ofn.lpstrTitle = TEXT("Open 512x512 image ...");
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    if(GetOpenFileName(&ofn))
    {
        file_len = wcslen(ofn.lpstrFile) + 1;

        wcstombs_s(&converted_len, converted_filename, file_len, ofn.lpstrFile, _TRUNCATE);

        if (converted_len != file_len) {
            play_error_sound();
            printf("Error: Can't open unicode paths.");
            opening_file = GL_FALSE;
            return;
        }

        if(load_image(converted_filename)) {
            draw_histogram(current_histogram);
        }
    }
    //Set the old working directory.
    SetCurrentDirectory(cur_dir);
    opening_file = GL_FALSE;
}