Results 1 to 3 of 3

Thread: 2D texture mapping in openGL and vc++(source code)

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    1

    2D texture mapping in openGL and vc++(source code)

    can anyone please help me in mapping a texture on a 2D object (to be more specific on a simple figure like a square)in openGL and vc++.I need a complete source code for it.Its really urgent....I will be really thankful if somebody does send me one

  2. #2
    Senior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: 2D texture mapping in openGL and vc++(source code)

    Hello,

    first you have to load a texture. Wether by the auxilery lib or with LoadImage

    Code :
    	CFile File;
    	ULONGLONG Length = 0;
    	GLuint tempID  = 0;
     
     
    	Length = File.GetLength();
    	HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, Filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);	
     
    	if(hBmp == NULL)
    	{
    		return FALSE;
    	}
     
    	BITMAP BM;                          // Get bitmap info.	
        GetObject (hBmp,sizeof (BM),&BM); //
     
    	if (BM.bmBitsPixel != 24)           // 24Bit-Bitmap?
    	{
    		return FALSE;                     
    	}
     
    	glGenTextures(1,&tempID);
    	glBindTexture(GL_TEXTURE_2D, tempID);
    	//glPixelStorei(GL_UNPACK_ALIGNMENT,4);  
    	//glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    	//glPixelStorei(GL_UNPACK_SKIP_ROWS,  0);
    	//glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);					 
    	glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGB,BM.bmWidth,BM.bmHeight,0,GL_RGB,GL_UNSIGNED_BYTE,BM.bmBits);
    	glBindTexture(GL_TEXTURE_2D, 0);
     
    // bind texture
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,tempID);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,0.0f); 
        glVertex3f(0.0f,0.0f,0.0f);
     
        glTexCoord2f(1.0f,0.0f); 
        glVertex3f(1.0f,0.0f,0.0f);
     
        glTexCoord2f(1.0f,1.0f); 
        glVertex3f(1.0f,1.0f,0.0f);
     
        glTexCoord2f(0.0f,1.0f); 
        glVertex3f(0.0f,1.0f,0.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: 2D texture mapping in openGL and vc++(source code)


Similar Threads

  1. opengl source code??
    By in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 11-24-2005, 04:16 AM
  2. do u have opengl source code?
    By john1234 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-13-2003, 10:24 AM
  3. OpenGL source code
    By shobha in forum OpenGL: Linux
    Replies: 1
    Last Post: 04-15-2003, 01:05 AM
  4. Replies: 0
    Last Post: 01-13-2003, 05:47 AM
  5. From 3DS to OpenGL c++ source code
    By clucches in forum OpenGL: Advanced Coding
    Replies: 39
    Last Post: 04-03-2001, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean