How to load 768*576 image in opengl ?
-
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
-
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
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++ -
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++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.
-
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.
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++