1
$\begingroup$

I have object loader, which i want to have background. I tried to put jpg image like texture to my application. I tried to make that with FreeImage library, but the image didn't show. Also i tried with Gdiplus, i opened the image but when i opened and the object the background disappeared. I send link with the code (with FreeImage library), If someone have any ideas i will be so happy, because I haven't yet.

https://github.com/Nushiii/viewer/blob/master/ViewerPicture%20FreeImege/ViewerPicture/main.cpp

EDIT:

       int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {

    MSG msg = {0};
    WNDCLASSEX wcl = {0};

    GLuint texture;
    float theta = 0.0f;

    wcl.cbSize = sizeof(wcl);
    wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    wcl.lpfnWndProc = WindowProc;
    wcl.cbClsExtra = 0;
    wcl.cbWndExtra = 0;
    wcl.hInstance = g_hInstance = hInstance;
    wcl.hIcon = static_cast<HICON>(LoadImage(hInstance,
    MAKEINTRESOURCE (IDI_ICON1),
    IMAGE_ICON,
    48, 48,    // or whatever size icon you want to load
    LR_DEFAULTCOLOR));
    wcl.hCursor = LoadCursor(0, IDC_ARROW);
    wcl.hbrBackground = 0;
    wcl.lpszMenuName = MAKEINTRESOURCE(MENU_FIXED_FUNC);
    wcl.lpszClassName = "GLWindowClass";
    wcl.hIconSm = 0;

    if (!RegisterClassEx(&wcl))
        return 0;

    g_hWnd = CreateAppWindow(wcl, APP_TITLE);

          // load our texture
      FIBITMAP  *dib1 = loadImage("angel.jpg");
      texture = LoadTexturee( dib1, TRUE );

    if (g_hWnd)
    {
        SetProcessorAffinity();

        if (Init())
        {
            ShowWindow(g_hWnd, nShowCmd);
            UpdateWindow(g_hWnd);

            while (true)
            {
                if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
                {
                    if (msg.message == WM_QUIT)
                        break;

                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                } else {

EDIT

                  UpdateFrame(GetElapsedTimeInSeconds());
                  DrawFrame(texture, g_hDC);
                  SwapBuffers(g_hDC);

                }

                if (msg.message == WM_QUIT)
                    break;

            }
        }

        Cleanup();
        UnregisterClass(wcl.lpszClassName, hInstance);
    }
    FreeTexture( texture );
    return static_cast<int>(msg.wParam);
}

EDIT: Now i load the picture, but the object doesn'n load.

VOID DrawFrame(GLuint texture,HDC hDC)
{ 

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();


  // setup texture mapping
 glEnable( GL_TEXTURE_2D );
 glBindTexture( GL_TEXTURE_2D, texture );

 glPushMatrix();
 glBegin( GL_QUADS );
 glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
 glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
 glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
 glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
 glEnd();
 glPopMatrix();

glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPopMatrix(); // Pops our orthographic projection matrix
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION); 
glLoadIdentity();
gluPerspective(CAMERA_FOVY,
   static_cast<float>(g_windowWidth) / static_cast<float> (g_windowHeight),
   CAMERA_ZNEAR, CAMERA_ZFAR);
    glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(g_cameraPos[0], g_cameraPos[1], g_cameraPos[2],
  g_targetPos[0], g_targetPos[1], g_targetPos[2],
  0.0f, 1.0f, 0.0f);

}

$\endgroup$
  • 2
    $\begingroup$ The normal way to draw a static background if to draw a static textured full-screen quad. $\endgroup$ – ratchet freak Sep 13 '16 at 13:25
  • $\begingroup$ @ratchetfreak please make that comment an answer, so we can vote it up :) $\endgroup$ – Paul-Jan Sep 14 '16 at 6:08
  • $\begingroup$ Without access to the code, it is difficult to guess what might have gone wrong. The link does not work for me (perhaps it requires you to be logged into your storage account). Would you be happy to paste the code here? If so you can edit and the question can be reopened. Until then I'm putting the question on hold so that there will be no further answers until it is clarified, to avoid further confusion. $\endgroup$ – trichoplax Sep 15 '16 at 8:58
  • $\begingroup$ @trichoplax what do you think about github or mail, becouse the code is long and i think that if you look the all code will be easier what i wrong. Thank you so much! $\endgroup$ – I.To Sep 15 '16 at 13:31
  • $\begingroup$ I recommend separating out just the part of the code that places the background, and seeing if it works on its own. If it doesn't, you can post just that part knowing that it contains a problem. If it does work, add in the simplest extra code that causes the problem, then post that slightly longer code knowing that it contains a problem. $\endgroup$ – trichoplax Sep 15 '16 at 18:13
5
$\begingroup$

Normally if you paint a background image you simply draw a textured full-screen square while depth testing and writing is disabled before drawing the actual scene (where you re-enable depth)

In the code you posted you draw the quad but then clear the screen again. Don't do that. Move the drawing of the quad from main to right after the glClear call.

$\endgroup$
  • $\begingroup$ I tried, but no result... $\endgroup$ – I.To Sep 15 '16 at 4:19
  • $\begingroup$ Or you simply put the square behind everything and render it same way as everything else. $\endgroup$ – joojaa Sep 16 '16 at 21:08
  • $\begingroup$ @joojaa Can you look my code and say me where i am wrong. I tried everything, but maybe there ware mistakes in my code. $\endgroup$ – I.To Sep 17 '16 at 12:11
  • $\begingroup$ @I.To I made an update, tl;dr you draw, clear and draw again move the first draw to after the clear. $\endgroup$ – ratchet freak Sep 17 '16 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.