<p>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)</p>

<p>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 <code>glClear</code> call.</p>

CC BY-SA 3.0
2016-09-15T04:19:29.677Z
I tried, but no result...
I.To
CC BY-SA 3.0
2016-09-16T21:08:18.380Z
Or you simply put the square behind everything and render it same way as everything else.
joojaa
CC BY-SA 3.0
2016-09-17T12:11:56.597Z
@joojaa Can you look my code and say me where i am wrong. I tried everything, but maybe there ware mistakes in my code.
I.To
CC BY-SA 3.0
2016-09-17T12:31:16.757Z
@I.To I made an update, tl;dr you draw, clear and draw again move the first draw to after the clear.
ratchet freak
CC BY-SA 3.0
2016-09-14T07:49:05.447Z
2016-09-17T12:30:43.597Z
2016-09-17T12:30:43.597Z
ratchet freak
<p>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.</p>

<p><a href="https://github.com/Nushiii/viewer/blob/master/ViewerPicture%20FreeImege/ViewerPicture/main.cpp" rel="nofollow">https://github.com/Nushiii/viewer/blob/master/ViewerPicture%20FreeImege/ViewerPicture/main.cpp</a></p>

<p><strong>EDIT:</strong></p>

<pre><code>       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&lt;HICON&gt;(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(&amp;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(&amp;msg, 0, 0, 0, PM_REMOVE))
                {
                    if (msg.message == WM_QUIT)
                        break;

                    TranslateMessage(&amp;msg);
                    DispatchMessage(&amp;msg);
                } else {
</code></pre>

<p><strong>EDIT</strong>              </p>

<pre><code>                  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&lt;int&gt;(msg.wParam);
}
</code></pre>

<p><strong>EDIT:</strong> <strong>Now i load the picture, but the object doesn'n load.</strong></p>

<pre><code>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&lt;float&gt;(g_windowWidth) / static_cast&lt;float&gt; (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);
</code></pre>

<p>}</p>

CC BY-SA 3.0
2016-09-13T13:25:42.010Z
The normal way to draw a static background if to draw a static textured full-screen quad.
ratchet freak
CC BY-SA 3.0
2016-09-14T06:08:37.170Z
@ratchetfreak please make that comment an answer, so we can vote it up :)
Paul-Jan
CC BY-SA 3.0
2016-09-15T08:58:45.180Z
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.
trichoplax is on Codidact now
CC BY-SA 3.0
2016-09-15T13:31:34.940Z
@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!
I.To
CC BY-SA 3.0
2016-09-15T18:13:48.977Z
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.
trichoplax is on Codidact now
CC BY-SA 3.0
2016-09-17T10:18:16.717Z
I did that. Do you have any ideas? @trichoplax
I.To
<opengl><3d><texture><legacy-opengl>
Background behind 3D model
I.To
# Background behind 3D model

(Asked by: username_0 on 2016-09-13)

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);

```

}

**Tags:** opengl, 3d, texture, legacy-opengl

> **Comments:**
> **username_1**: The normal way to draw a static background if to draw a static textured full-screen quad.  
> **username_2**: @username_1 please make that comment an answer, so we can vote it up :)  
> **username_3**: 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.  
> **username_0**: @username_3 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!  
> **username_3**: 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.  
> **username_0**: I did that. Do you have any ideas? @username_3  

---

## 1 answers

### Answer by username_1 on 2016-09-14. Score: 5 | Accepted answer

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.

> **Comments:**
> **username_0**: I tried, but no result...  
> **username_4**: Or you simply put the square behind everything and render it same way as everything else.  
> **username_0**: @username_4 Can you look my code and say me where i am wrong. I tried everything, but maybe there ware mistakes in my code.  
> **username_1**: @username_0 I made an update, tl;dr you draw, clear and draw again move the first draw to after the clear.  

---

