Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been trying to draw a bitmap int array using glTexImage2D, but it only outputs white nothingness. It outputs jumbled messy pixels from out of bounds memory if I initialize the int aray as a char array instead, but it only renders whiteness if I try casting an int array to a char array.

What I have tried:

I've even tried using memcpy to copy the ints to a 4x larger array called PixelsTemp, but it's still white for some reason. If I manually change some values in PixelsTemp[211], it will show a single blue pixel, but nothing from the memcpy shows somehow. It makes no sense, because PixelsTemp actually works with glDrawPixels just fine, but it's just nothing but white with glTexImage2D. Please help.

C++
void beginRefresh() {
            //BITMAPINFO bmi = tbmi;
            //while (true) {                                                      //v these may be important later
            //StretchDIBits(bp, 0, 0, realwidth, realheight, 0, 0, width, height, Pixels, &bmi, DIB_RGB_COLORS, SRCCOPY);

            /*glDrawPixels(width,
                height,
                GL_RGBA,
                GL_UNSIGNED_BYTE,
                Pixels);*/
            unsigned char* PixelsTemp = new unsigned char[width * height * 4];
            memcpy(PixelsTemp, Pixels, width * height * 4);

            glEnable(GL_TEXTURE_2D);
            glGenTextures(1, &glBuffer);
            glBindTexture(GL_TEXTURE_2D, glBuffer);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
            //unsigned char* PixelsTemp = (unsigned char*)Pixels;
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, PixelsTemp);
            UpdateViewport();
            glClear(GL_COLOR_BUFFER_BIT); // Thanks Benedani!
            glViewport(nViewX, nViewY, nViewW, nViewH);
            glBegin(GL_QUADS);
            glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f + (fSubPixelOffsetX), -1.0f + (fSubPixelOffsetY), 0.0f);
            glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f + (fSubPixelOffsetX), 1.0f + (fSubPixelOffsetY), 0.0f);
            glTexCoord2f(1.0, 0.0); glVertex3f(1.0f + (fSubPixelOffsetX), 1.0f + (fSubPixelOffsetY), 0.0f);
            glTexCoord2f(1.0, 1.0); glVertex3f(1.0f + (fSubPixelOffsetX), -1.0f + (fSubPixelOffsetY), 0.0f);
            glEnd();
            //glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, PixelsTemp);
            delete[] PixelsTemp;

            SwapBuffers(glDeviceContext);
        }
Posted
Updated 20-Apr-23 22:12pm

1 solution

I don't have an answer for you but here are a few sample projects you might get a hint from :
50 OpenGL Win32 Projects in One[^]
50 OpenGL MFC Projects in One[^]
Your Own Quadrics in OpenGL MFC[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900