Results 1 to 7 of 7

Thread: Binding a texture in a class

  1. #1

    Binding a texture in a class

    Im trying to bind a texture to a Quadrilateral in a class Quad

    ive used a fair chunk of code from Nehe's Tutorial 7, but i cant get it to apply the texture.

    The vertice drawing code works and allows textured polygons, however this code makes the quad white all over, as if i hadnt enabled GL_TEXTURE_2D.

    I cant figure out why it isnt working, all the correct lines execute, ive stepped through it with a debugger, the file exists and the line ive used to call the function is

    CQuad Q;

    then later


    Code :
    //Apply A Bitmap File Texture to a polygon
    void CQuad::ApplyTexture(const char *cpInput)
     	//If so, calculate Texture Doodads. ( i dont understand how it works)
    	//Do We Have a texture?
    	if(cpInput) //yes we have a texture
     		//Check that it exists.
    		fstream TexFile(cpInput, ios::in | ios:: binary);
     		cpTextureFile = new char[strlen(cpInput)+1];
     		//copy strings (to <- from)
     		strcpy(cpTextureFile, cpInput);
    	else //We Dont have a texture
     		cpTextureFile = 0;
       		bIsTextured = false;
    	if (strlen(cpInput)) //Is a non null string
    		glEnable(GL_TEXTURE_2D);	// Enable Texture Mapping ( NEW )
    		//Yes We Are Texxing
    		bIsTextured = true;
    		//GL Texture Info
    		AUX_RGBImageRec *TextureImage;
    		// Load The Bitmap
    		glGenTextures(1, &amp;texture);					// Create Texture
    		// Create Nearest mipmapped Texture
    		glBindTexture(GL_TEXTURE_2D, texture);
    		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage->sizeX, TextureImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
    		delete TextureImage->data;				// Free The Texture Image Memory
    		delete TextureImage;						// Free The Image Structure
    //Draws the Quad using OpenGL 
    //if a texture is specified, enable texturing
    void CQuad: [img][/img]raw(CPosition CDrawOrigin)
    	if (bIsTextured)
    		glEnable(GL_TEXTURE_2D);	// Enable Texture Mapping 	 	
    		glDisable(GL_TEXTURE_2D);	//No Texture for you.
    		//Vertex 1 of 4
      			glTexCoord2f(0.0f, 0.0f); // Bottom Left Of The Texture
    		CVertice[0].Draw(CDrawOrigin, bIsTextured);
    		//Vertex 2 of 4
        		glTexCoord2f(1.0f, 0.0f); // Bottom Right Of The Texture
    		CVertice[1].Draw(CDrawOrigin, bIsTextured);
      		//Vertex 3 of 4        
    		    glTexCoord2f(1.0f, 1.0f);	// Top Right Of The Texture
       		CVertice[2].Draw(CDrawOrigin, bIsTextured);
            //Vertex 4 of 4        
              	glTexCoord2f(0.0f, 1.0f);	// Top Left Of The Texture 
       		CVertice[3].Draw(CDrawOrigin, bIsTextured);

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Melbourne, Australia

    Re: Binding a texture in a class

    Make sure auxDIBImageLoad(..) doesn't return 0.
    One more thing is you probably wanted to have:
    delete[] TextureImage->data;
    in your code, rather than:
    delete TextureImage->data;
    ..but it's not white texture related

  3. #3

    Re: Binding a texture in a class

    What causes auxDIBImageLoad to return 0?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Melbourne, Australia

    Re: Binding a texture in a class

    Usually loaders return 0 in case loading failed, auxDIBImageLoad is probably the same about returned values.

    [This message has been edited by MickeyMouse (edited 12-12-2002).]

  5. #5

    Re: Binding a texture in a class

    I just noticed that it is not always solid white

    it is solid whatever i put in the call to glColour4f(..)

  6. #6

    Re: Binding a texture in a class

    Figured it out, i was calling ApplyTexture before i had properly initialised the window. stupid me

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Shreveport, LA, USA

    Re: Binding a texture in a class

    In other words, you didn't have an active render context. Without one of those, most OpenGL functions will simply fail quietly.

Similar Threads

  1. Binding Index Buffer Before Binding Vertex Array Causes Black Screen.
    By babaliaris in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-14-2018, 04:14 PM
  2. Replies: 0
    Last Post: 11-12-2014, 04:41 AM
  3. Texture and lighting + class structure.
    By Muckle_ewe in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 04-14-2012, 01:41 PM
  4. GL3 and texture binding
    By V-man in forum OpenGL: Advanced Coding
    Replies: 24
    Last Post: 08-26-2007, 10:40 AM
  5. My Texture Class + A Question about an Addition..
    By cutting_crew in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 11-06-2003, 06:15 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