Click here to Skip to main content
15,907,396 members
Home / Discussions / Graphics
   

Graphics

 
AnswerRe: please Pin
Tim Craig29-Oct-09 15:35
Tim Craig29-Oct-09 15:35 
GeneralRe: please Pin
Archy_Yu29-Oct-09 16:50
Archy_Yu29-Oct-09 16:50 
GeneralRe: please Pin
Luc Pattyn29-Oct-09 17:38
sitebuilderLuc Pattyn29-Oct-09 17:38 
QuestionDirectx Pin
messages25-Oct-09 3:30
messages25-Oct-09 3:30 
AnswerRe: Directx Pin
Baltoro29-Oct-09 11:13
Baltoro29-Oct-09 11:13 
GeneralRe: Directx Pin
messages31-Oct-09 4:02
messages31-Oct-09 4:02 
GeneralRe: Directx Pin
Baltoro1-Nov-09 11:29
Baltoro1-Nov-09 11:29 
QuestionMy texture just didnot work! Anyone give a hand? Pin
Archy_Yu24-Oct-09 1:41
Archy_Yu24-Oct-09 1:41 
     unsigned int ID;                 /**< 生成纹理的ID号 */
   int imageWidth;                  /**< 图像宽度 */
   int imageHeight;                 /**< 图像高度 */
   unsigned char *image;            /**< 指向图像数据的指针 */
     FILE *pFile = 0;


 BITMAPINFOHEADER bitmapInfoHeader;
 BITMAPFILEHEADER header;

 unsigned char textureColors = 0;

 pFile = fopen("桌面.bmp", "rb");
     if(pFile == 0) return false;

 fread(&header, sizeof(BITMAPFILEHEADER), 1, pFile);

 if(header.bfType != BITMAP_ID)
    {
        fclose(pFile);
        return false;
    }

 fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, pFile);

 imageWidth = bitmapInfoHeader.biWidth;
 imageHeight = bitmapInfoHeader.biHeight;


if(bitmapInfoHeader.biSizeImage == 0)
   bitmapInfoHeader.biSizeImage = bitmapInfoHeader.biWidth *
   bitmapInfoHeader.biHeight * 3;


 fseek(pFile, header.bfOffBits, SEEK_SET);


 image = new unsigned char[bitmapInfoHeader.biSizeImage];


 fread(image, 1, bitmapInfoHeader.biSizeImage, pFile);


 for(int index = 0; index < (int)bitmapInfoHeader.biSizeImage; index+=3)
    {
        textureColors = image[index];
        image[index] = image[index + 2];
        image[index + 2] = textureColors;
    }

 fclose(pFile);
 glPixelStorei(GL_UNPACK_ALIGNMENT,1);

 glGenTextures(1, &ID);

 glBindTexture(GL_TEXTURE_2D, ID);

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

 gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imageWidth,
                   imageHeight, GL_RGB, GL_UNSIGNED_BYTE,
                   image);

 glEnable(GL_TEXTURE_2D);
 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

 glPushMatrix();
 glScaled(45.0,30.0,0);
 glBindTexture(GL_TEXTURE_2D, ID);
 glBegin(GL_QUADS);
     glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.0f, -1.0f, 0.0f);
     glTexCoord2f(1.0f, 0.0f); glVertex3f(-2.0f,  1.0f, 0.0f);
     glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f,  1.0f, 0.0f);
     glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -1.0f, 0.0f);

 glEnd();
 glPopMatrix();

GLvoid ReShapeGLScene( GLsizei width,GLsizei height )
{
glViewport(0,0,(GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho((GLdouble)-450.0,(GLdouble)450.0,(GLdouble)-300.0,(GLdouble)300.0,50.0,-10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


I think i must be somewhere wrong ,but i am not a expert,and cannot find it .The followings are some set about my code
static PIXELFORMATDESCRIPTOR  pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW|
			PFD_SUPPORT_OPENGL|
			PFD_DOUBLEBUFFER,
			PFD_TYPE_RGBA,
			24,
			0,0,0,0,0,0,
			0,
			0,
			0,
			0,0,0,0,
			32,
			0,
			0,
			PFD_MAIN_PLANE,
			0,
			0,0,0			
	};



thanks advance
GeneralRe: My texture just didnot work! Anyone give a hand? Pin
IdUnknown26-Oct-09 3:22
IdUnknown26-Oct-09 3:22 
GeneralRe: My texture just didnot work! Anyone give a hand? Pin
Archy_Yu26-Oct-09 4:49
Archy_Yu26-Oct-09 4:49 
AnswerRe: My texture just didnot work! Anyone give a hand? Pin
Tim Craig26-Oct-09 7:41
Tim Craig26-Oct-09 7:41 
GeneralRe: My texture just didnot work! Anyone give a hand? Pin
Archy_Yu26-Oct-09 20:11
Archy_Yu26-Oct-09 20:11 
QuestionGrayscale values Pin
econner21-Oct-09 20:32
econner21-Oct-09 20:32 
AnswerRe: Grayscale values Pin
ely_bob27-Oct-09 5:22
professionalely_bob27-Oct-09 5:22 
QuestionChoose correct pixel (Intertesting problem) Pin
mah_pankaj20-Oct-09 16:12
mah_pankaj20-Oct-09 16:12 
AnswerRe: Choose correct pixel (Intertesting problem) Pin
Tim Craig20-Oct-09 19:27
Tim Craig20-Oct-09 19:27 
GeneralRe: Choose correct pixel (Intertesting problem) Pin
mah_pankaj21-Oct-09 0:47
mah_pankaj21-Oct-09 0:47 
GeneralRe: Choose correct pixel (Intertesting problem) Pin
Tim Craig21-Oct-09 6:06
Tim Craig21-Oct-09 6:06 
GeneralRe: Choose correct pixel (Intertesting problem) Pin
mah_pankaj26-Nov-09 18:57
mah_pankaj26-Nov-09 18:57 
QuestionIDirectDrawSurface::IsLost() never returns Pin
Code-o-mat20-Oct-09 4:25
Code-o-mat20-Oct-09 4:25 
QuestionReading an image Pin
xoxoxoxoxoxox16-Oct-09 8:02
xoxoxoxoxoxox16-Oct-09 8:02 
AnswerRe: Reading an image Pin
ely_bob27-Oct-09 6:01
professionalely_bob27-Oct-09 6:01 
QuestionHow to convert bmp 32bpp image Pin
FrederikL616-Oct-09 2:24
FrederikL616-Oct-09 2:24 
AnswerRe: How to convert bmp 32bpp image Pin
enhzflep20-Oct-09 19:28
enhzflep20-Oct-09 19:28 
Questionbackground in OpenGL Pin
Ben_King14-Oct-09 22:43
Ben_King14-Oct-09 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.