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?

Member Avatar for RudyM

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();
}
Member Avatar for RudyM

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

commented: My mistake. It's the OP that needs this. +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.