المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to load 768*576 image in opengl ?



C++ Programming
01-28-2011, 09:31 PM
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 (); // Reset The Projection Matrix

gluPerspective (45.0f, (GLfloat)(iwidth)/(GLfloat)(iHeight),1.0f, 100.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity ();
return TRUE; // Window Creating Was A Success
// Initialization Will Be Done In WM_CREATE
}

BOOL CTestDlg::Initialize()
{
// Start Of User Initialization
angle = 1.0f;
// Set Starting Angle To Zero // Grab A Device Context For Our Dib
glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Set Texture Max Filter
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // Set Texture Min Filter

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set The Texture Generation Mode For S To Sphere Mapping
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set The Texture Generation Mode For T To Sphere Mapping

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256,256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
return TRUE; // Return TRUE (Initialization Successful)
}
void CTestDlg::Draw() // Draw Our Scene
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
int i,j;
LoadBmpFile("C:\\test.bmp",i,j);
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,i, j, GL_RGB, GL_UNSIGNED_BYTE, data);

if (TRUE) // Is Background Visible?
{
glLoadIdentity(); // Reset The Modelview Matrix
glBegin(GL_QUADS); // Begin Drawing The Background (One Quad)
// Front Face
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-11.0f, -8.3f, -20.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 11.0f, -8.3f, -20.0f);
glEnd(); // Done Drawing The Background
}
glFlush (); // Flush The GL Rendering Pipeline

}