2

画像を全画面表示し、一連の画像をすばやく (144hz) 繰り返しフラッシュするだけのアプリケーションを作成しようとしています。私は OpenGL を見始めたばかりで、いくつかのチュートリアルを実行しましたが、ここで何が間違っているのかわかりません。私が立ち往生している部分は、実際には白い正方形としてしか表示されないため、画像をディスプレイにレンダリングすることです。これについて他のスタックオーバーフローの質問をしましたが、どの提案もうまくいきませんでした。

私はwin32アプリケーションを使用してVisual Studio 2015でこれを行っており、NupenGLパッケージをインストールしています。テスト目的で、256x256 ビットマップ イメージを使用しており、ビルドして静的にリンクした SOIL ライブラリを介してロードしています。

私は当初、SOIL ライブラリを適切にビルド/リンクしていなかったので、イメージを読み込もうとして奇妙なことが起こっていると考えていました。動作しないカスタム BMP ローダーを作成し、他の人の BMP ローダーをスタック オーバーフローで試してみましたが、役に立ちませんでした。テクスチャのロードではなく、実際にレンダリングしようとしたときに何かを台無しにしていると今では信じています。また、以下のコードでは、テクスチャが無効な場合に出力しますが、常に正常に戻ります。

出力 (フルスクリーン): ここに画像の説明を入力

出力 (WINDOWED): ここに画像の説明を入力

私のコード:

#include <gl/freeglut.h>
#include <stdio.h>
#include <iostream>
#include "SOIL.h"

void init();
void display(void);
void keyPressed(unsigned char key, int x, int y);
void resize(int heightY, int widthX);


//  define the window position on screen
int window_x;
int window_y;

//  variables representing the window size
int window_width = 480;
int window_height = 480;

//  variable representing the window title
char *window_title = "Resolution Enhancement via Display Vibrations";

bool fullscreen = false;

//-------------------------------------------------------------------------
//  Program Main method.
//-------------------------------------------------------------------------
void main(int argc, char **argv)
{
    //  Connect to the windowing system + create a window
    //  with the specified dimensions and position
    //  + set the display mode + specify the window title.
    glutInit(&argc, argv);
    glutInitWindowSize(window_width, window_height);
    glutInitWindowPosition(window_x, window_y);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutCreateWindow(window_title);

    glutFullScreen();

    // Setup keyPressed
    glutKeyboardFunc(keyPressed);

    // Handler for when the screen resizes
    glutReshapeFunc(resize);

    //  Set OpenGL program initial state.
    init();

    // Set the callback functions
    glutDisplayFunc(display);

    //  Start GLUT event processing loop
    glutMainLoop();
}

//-------------------------------------------------------------------------
//  Set OpenGL program initial state.
//-------------------------------------------------------------------------
void init()
{
    //  Set the frame buffer clear color to black. 
    glClearColor(0.0, 0.0, 0.0, 0.0);
}

//-------------------------------------------------------------------------
//  This function is passed to glutDisplayFunc in order to display 
//  OpenGL contents on the window.
//-------------------------------------------------------------------------
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);
    GLuint texture = SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture
    (
        "C:/Users/joeja/Desktop/Grass.bmp",
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );

    if (texture == 0) {
        std::cout << "Texture not found!\n" << std::endl;
    }
    else
    {
        std::cout << "Texture is good\n" << std::endl;
    }

    glBindTexture(GL_TEXTURE_2D, texture);

    glBegin(GL_QUADS);  // front face
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.5f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.5f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
    glEnd();

    glutSwapBuffers();
}

void resize(int heightY,int widthX) {
    const float ar = (float)widthX / (float)heightY;
    glViewport(0, 20, widthX, heightY);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar + 1, ar - 1, -1.0, 1.0, 2.0, 90.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void keyPressed(unsigned char key, int x, int y) {
    switch (key) {
    case 27:
    case 70:
    case 102: /* Fullscreen mode (Additional) : f/F */
        fullscreen = !fullscreen;
        if (fullscreen)
        {
            glutFullScreen();                /* Go to full screen */
        }
        else
        {
            glutReshapeWindow(800, 600);        /* Restore us */
            glutPositionWindow(0, 0);
        }
        break;
    }
}
4

1 に答える 1