What's new

Video Plugin in OpenGL and C/C++

tylerbingham

New member
I am having a problem with my Block() function. It changes the previous blocks to the current block type. I need a Tetris type draw function...where each time I call Block() I get a different block type, but the blocks already drawn stay the same instead of changing to the new block type. Here is the Block() function

void Block(int block_number) //Changed
{
glColor3f(1,1,1);
glPushMatrix();
glTranslatef(0,0,-8);
glTranslatef(block_x[block_number], block_y [block_number],0);
glRotatef(r,0,0,1);
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(0,0.3f);
glVertex2f(0.5f,0.3f);
glVertex2f(0.5f,0);
glEnd();
glPopMatrix();
}

Thanx y'all
 

Cyberman

Moderator
Moderator
Code:
void Block(int block_number) //Changed
{
  glColor3f(1,1,1); 
  glPushMatrix();
  glTranslatef(0,0,-8);
  glTranslatef(block_x[block_number], block_y [block_number],0);
  glRotatef(r,0,0,1); 
  glBegin(GL_QUADS); 
  glVertex2f(0,0);
  glVertex2f(0,0.3f);
  glVertex2f(0.5f,0.3f);
  glVertex2f(0.5f,0);
  glEnd();
  glPopMatrix();
}

Shouldn't you translate it AFTER you draw it instead of before?

In other words.

You push the matrix, create an object then you translate it to the location you want and then restore the matrix information.

Otherwise you are translating it first then creating something at a specific location then poping the matrix.. you aren't actually moving anything, unless I have something wrong in my head.
SO see if this works instead
Code:
void Block(int block_number) //Changed
{
  glColor3f(1,1,1); 
  glPushMatrix();
  glTranslatef(0,0,-8);
  glRotatef(r,0,0,1); 
  glBegin(GL_QUADS); 
  glVertex2f(0,0);
  glVertex2f(0,0.3f);
  glVertex2f(0.5f,0.3f);
  glVertex2f(0.5f,0);
  glTranslatef(block_x[block_number], block_y [block_number],0);
  glEnd();
  glPopMatrix();
}
 

Top