Solved

Texture binding not working in OpenGL

Posted on 2007-11-19
1
1,262 Views
Last Modified: 2013-12-21
I cannot get the texture working in my little bowling game. The BowlingScene is a box, like a room, but the texture in the wall was not displayed, why this could happen?
class BowlingScene : public Figure3d
{
private:
GLuint texture1;
 
public:
BowlingScene(double x, double y, double z,double rx, double ry, double rz);
void Draw();
};
 
 
 
 
 
 
BowlingScene::BowlingScene(double x, double y, double z,double rx, double ry, double rz)
{
    glGenTextures(0,&(this->texture1));
    AUX_RGBImageRec *imagenTextura1;
    imagenTextura1 = auxDIBImageLoad("textures\\background.bmp");
    glBindTexture(GL_TEXTURE_2D,this->texture1);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,imagenTextura1->sizeX,
	imagenTextura1->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,imagenTextura1->data);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);     //GL_NEAREST
 
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);     //GL_NEAREST
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);     //GL_NEAREST
 
    delete imagenTextura1;
 
    // OTHER CONSTRUCTOR CODE
}
 
 
 
 
 
void BowlingScene::Draw()
{
    glPushMatrix();   //guardar la matriz actual
    glTranslated(pos.x, pos.y, pos.z); //trasladar (modifica la matriz actual)
 
    glColor3f(1.0,1.0,0.0);
    glPointSize(10);
    GLfloat brillo[] = { 50 };
    GLfloat color[] = { 0.0, 0.5, 0.5, 1.0 };
    GLfloat specular[] = { 0.4, 0.4, 0.4, 1.0 };
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, brillo);
 
    double bottom = -50, ceil = 600,
        left = -600, right = 670,
        back = 2200, front = -50;
 
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, this->texture1);
 
        glBegin(GL_QUAD_STRIP);
 
    // Cara fondo
    glTexCoord2f(0,0);
    glVertex3d(left,bottom,front);
    glTexCoord2f(0,1);
    glVertex3d(left,ceil,front);
    glTexCoord2f(1,0);
    glVertex3d(right,bottom,front);
    glTexCoord2f(1,1);
    glVertex3d(right,ceil,front);
 
    glColor3d(0.5,0.8,0.4);
 
    // ETC...........
}

Open in new window

0
Comment
Question by:avatar-e
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
ikework earned 500 total points
ID: 20318141
hi avatar-e,

the first param of glGetTextures is the count of textures to generate, instead of 0 put 1


ike
BowlingScene::BowlingScene(double x, double y, double z,double rx, double ry, double rz)
{
    glGenTextures(1,&(this->texture1));  // << here put 1 instead of 0
    AUX_RGBImageRec *imagenTextura1;
    imagenTextura1 = auxDIBImageLoad("textures\\background.bmp");
    glBindTexture(GL_TEXTURE_2D,this->texture1);

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Data Analysis 7 57
How do I pin a shortcut to the taskbar in Windows 7? 3 30
Windows 10 Sound Driver Issue 26 49
Unable to start workstation service 12 210
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question