0

void PatratTexturat(PATRAT patrat, int numar) { switch(numar) { case 1: if(numar==1) glBindTexture(GL_TEXTURE_2D, id_textura[2]); else glBindTexture(GL_TEXTURE_2D,id_textura[3]); break; case 2: if(numar==2) glBindTexture(GL_TEXTURE_2D, id_textura[4]); else glBindTexture(GL_TEXTURE_2D, id_textura[5]); break; case 3: if(numar==3) glBindTexture(GL_TEXTURE_2D, id_textura[6]); else glBindTexture(GL_TEXTURE_2D, id_textura[7]); case 4: if(numar==4) { glBindTexture(GL_TEXTURE_2D, id_textura[8]); } else { glBindTexture(GL_TEXTURE_2D, id_textura[9]); } break; case 5: glBindTexture(GL_TEXTURE_2D,id_textura[10]); break; case 6: glBindTexture(GL_TEXTURE_2D,id_textura[11]); break; case 7: glBindTexture(GL_TEXTURE_2D,id_textura[12]); break; case 8: glBindTexture(GL_TEXTURE_2D,id_textura[13]); break; case 9: glBindTexture(GL_TEXTURE_2D,id_textura[14]); break; default: glBindTexture(GL_TEXTURE_2D, NULL); break; } glBegin(GL_QUADS); glTexCoord2f(0.0,0.0); glVertex2f(patrat.stanga,patrat.jos); glTexCoord2f(1.0,0.0); glVertex2f(patrat.dreapta,patrat.jos); glTexCoord2f(1.0,1.0); glVertex2f(patrat.dreapta,patrat.sus); glTexCoord2f(0.0,1.0); glVertex2f(patrat.stanga,patrat.sus); glEnd(); } I have the code above and i get the error that case may only be used in a switch statement, and with break the same error. Am i missing some braces?

2
Contributors
2
Replies
15
Views
1 Year
Discussion Span
Last Post by RudyM
0

Case 2 should have its break statement outside the conditionals; it was within the else block.
Case 3 needs a break statement.

These were just small changes made here; I spent most of the time breaking this out into readable code:

void PatratTexturat (PATRAT patrat, int numar)
{
  switch(numar)
  { 
    case 1: 
      if(numar==1)
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[2]); 
      }
      else
      {
        glBindTexture(GL_TEXTURE_2D,id_textura[3]); 
      }
      break; 
    case 2: 
      if(numar==2)
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[4]); 
      }
      else
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[5]); 
      }
      break; 
    case 3:
      if(numar==3)
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[6]);
      }
      else
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[7]); 
      }
      break;
    case 4:
      if(numar==4)
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[8]); 
      }
      else
      {
        glBindTexture(GL_TEXTURE_2D, id_textura[9]);
      }
      break; 
    case 5:
      glBindTexture(GL_TEXTURE_2D,id_textura[10]); 
      break; 
    case 6: 
      glBindTexture(GL_TEXTURE_2D,id_textura[11]); 
      break; 
    case 7: 
      glBindTexture(GL_TEXTURE_2D,id_textura[12]); 
      break; 
    case 8: 
      glBindTexture(GL_TEXTURE_2D,id_textura[13]); 
      break; 
    case 9: 
      glBindTexture(GL_TEXTURE_2D,id_textura[14]); 
      break; 
    default: 
      glBindTexture(GL_TEXTURE_2D, NULL); 
      break; 
  } 

  glBegin(GL_QUADS); 
  glTexCoord2f(0.0,0.0); 
  glVertex2f(patrat.stanga,patrat.jos); 
  glTexCoord2f(1.0,0.0); 
  glVertex2f(patrat.dreapta,patrat.jos); 
  glTexCoord2f(1.0,1.0); 
  glVertex2f(patrat.dreapta,patrat.sus); 
  glTexCoord2f(0.0,1.0); 
  glVertex2f(patrat.stanga,patrat.sus); 
  glEnd();
}
1

So a down-vote for my not knowing this was a duplicate posting?

Votes + Comments
My mistake. It's the OP that needs this.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.