Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to load 768*576 image in opengl ?

How to load 768*576 image in opengl ?

Scheduled Pinned Locked Moved C / C++ / MFC
announcementgraphicsquestiongame-devtutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GAJERA
    wrote on last edited by
    #1

    HI ALL I am trying to load image buffer and update image buffer per second . The function can load 256*256 image or 512*512 image but it can not load 768*576 image. I apply it with following function,Please let me know how can i load 768*576 image buffer?. int iwidth=768; int iHeight=512; unsigned char* data = 0; float angle=1.0f; BOOL CTestDlg::CreateWindowGL(HWND window) // This Code Creates Our OpenGL Window { DWORD windowStyle = WS_OVERLAPPEDWINDOW; // Define Our Window Style DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style int iBitperPixel=16; PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof (PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format iBitperPixel, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; GLuint PixelFormat; // Will Hold The Selected Pixel Format CDC *pDc= GetDC(); // Grab A Device Context For This Window PixelFormat = ChoosePixelFormat (pDc->m_hDC, &pfd); // Find A Compatible Pixel Format if (SetPixelFormat (pDc->m_hDC, PixelFormat, &pfd) == FALSE) // Try To Set The Pixel Format { // Failed ReleaseDC (pDc); // Release Our Device Context // Zero The Window Handle return FALSE; // Return False } hRC = wglCreateContext (pDc->m_hDC); // Try To Get A Rendering Context // Make The Rendering Context Our Current Rendering Context if (wglMakeCurrent (pDc->m_hDC, hRC) == FALSE) return FALSE; glViewport (0, 0, (GLsizei)(iwidth), (GLsizei)(iHeight)); // Reset The Current Viewport glMatrixMode (GL_PROJECTION); // Select The Projection Matrix glLoadIdentity (); // Re

    C 1 Reply Last reply
    0
    • G GAJERA

      HI ALL I am trying to load image buffer and update image buffer per second . The function can load 256*256 image or 512*512 image but it can not load 768*576 image. I apply it with following function,Please let me know how can i load 768*576 image buffer?. int iwidth=768; int iHeight=512; unsigned char* data = 0; float angle=1.0f; BOOL CTestDlg::CreateWindowGL(HWND window) // This Code Creates Our OpenGL Window { DWORD windowStyle = WS_OVERLAPPEDWINDOW; // Define Our Window Style DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style int iBitperPixel=16; PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof (PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format iBitperPixel, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; GLuint PixelFormat; // Will Hold The Selected Pixel Format CDC *pDc= GetDC(); // Grab A Device Context For This Window PixelFormat = ChoosePixelFormat (pDc->m_hDC, &pfd); // Find A Compatible Pixel Format if (SetPixelFormat (pDc->m_hDC, PixelFormat, &pfd) == FALSE) // Try To Set The Pixel Format { // Failed ReleaseDC (pDc); // Release Our Device Context // Zero The Window Handle return FALSE; // Return False } hRC = wglCreateContext (pDc->m_hDC); // Try To Get A Rendering Context // Make The Rendering Context Our Current Rendering Context if (wglMakeCurrent (pDc->m_hDC, hRC) == FALSE) return FALSE; glViewport (0, 0, (GLsizei)(iwidth), (GLsizei)(iHeight)); // Reset The Current Viewport glMatrixMode (GL_PROJECTION); // Select The Projection Matrix glLoadIdentity (); // Re

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Please, in the future read the posting guidelines before posting (for instance, use the pre tags to format your code properly so that it is readable). Now to your question: OpenGL only handle images which have a power of 2 as dimensions. Loading images with non-standard dimensions will work on certain graphic cards but not all of them. So, the solution to your problem is to simply create your image as a 1024x1024 image (for instance, additional space is filled with white) and then when the image is used (using glTexCoord2) you only take the part where your image really is (for instance if your image is 768 pixels wide, you have to specify 768/1024=0.75 in your glTexCoord function).

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      G 1 Reply Last reply
      0
      • C Cedric Moonen

        Please, in the future read the posting guidelines before posting (for instance, use the pre tags to format your code properly so that it is readable). Now to your question: OpenGL only handle images which have a power of 2 as dimensions. Loading images with non-standard dimensions will work on certain graphic cards but not all of them. So, the solution to your problem is to simply create your image as a 1024x1024 image (for instance, additional space is filled with white) and then when the image is used (using glTexCoord2) you only take the part where your image really is (for instance if your image is 768 pixels wide, you have to specify 768/1024=0.75 in your glTexCoord function).

        Cédric Moonen Software developer
        Charting control [v3.0] OpenGL game tutorial in C++

        G Offline
        G Offline
        GAJERA
        wrote on last edited by
        #3

        int iwidth=512; int iHeight=512; OK,Now i am create image 512*512 and give in glTexImage2D

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, iwidth,iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

        In Draw Function

        glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,768, 576, GL_RGB, GL_UNSIGNED_BYTE, data);

        float fval=(float)(768.0f/512.0f);//.75f;
        if (TRUE) // Is Background Visible?
        {
        // Reset The Modelview Matrix
        glBegin(GL_QUADS); // Begin Drawing The Background (One Quad)
        // Front Face
        glTexCoord2f(fval, fval);
        glVertex3f( 11.0f, 8.3f, -20.0f);
        glTexCoord2f(0.0f, fval);
        glVertex3f(-11.0f, 8.3f, -20.0f);
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-11.0f, -8.3f, -20.0f);
        glTexCoord2f(fval, 0.0f);
        glVertex3f( 11.0f, -8.3f, -20.0f);
        glEnd(); // Done Drawing The Background
        }

        I can not able to load image like above coding. By the way,My view size if fix 512*512 and i want to support zoom also.

        C 1 Reply Last reply
        0
        • G GAJERA

          int iwidth=512; int iHeight=512; OK,Now i am create image 512*512 and give in glTexImage2D

          glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, iwidth,iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

          In Draw Function

          glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,768, 576, GL_RGB, GL_UNSIGNED_BYTE, data);

          float fval=(float)(768.0f/512.0f);//.75f;
          if (TRUE) // Is Background Visible?
          {
          // Reset The Modelview Matrix
          glBegin(GL_QUADS); // Begin Drawing The Background (One Quad)
          // Front Face
          glTexCoord2f(fval, fval);
          glVertex3f( 11.0f, 8.3f, -20.0f);
          glTexCoord2f(0.0f, fval);
          glVertex3f(-11.0f, 8.3f, -20.0f);
          glTexCoord2f(0.0f, 0.0f);
          glVertex3f(-11.0f, -8.3f, -20.0f);
          glTexCoord2f(fval, 0.0f);
          glVertex3f( 11.0f, -8.3f, -20.0f);
          glEnd(); // Done Drawing The Background
          }

          I can not able to load image like above coding. By the way,My view size if fix 512*512 and i want to support zoom also.

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          That doesn't make any sense: tell me how you put an 768x768 image in an 512x512 image :confused: How large is your image finally ? Because your fval (768/512) is bigger than 1 (and so, it is invalid for the glTexCoord function).

          Cédric Moonen Software developer
          Charting control [v3.0] OpenGL game tutorial in C++

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups