Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I wanted to learn to develop games so started with tetris. I encountered a problem right in the beginning. My game is 20% ready. There are five types of shapes viz YELL, BOX, LINE, TEE, YEL which are shapes of different kinds. I created five display lists like this

#define YELL 1
#define BOX 2
#define LINE 3
#define TEE 4
#define YEL 5
int bs=20;
void defineshapes()
{
glNewList(YELL,GL_COMPILE);
    glPushMatrix();
    glTranslated(-bs,0,0);
    glColor3fv(color[color1]);
    glBegin(GL_POLYGON);
    glVertex2i(0,0);
    glVertex2i(bs,0);
    glVertex2i(bs,-bs);
    glVertex2i(0,-bs);
    glEnd();
    glTranslated(bs,0,0);
    glColor3fv(color[color2]);
    glBegin(GL_POLYGON);
    glVertex2i(0,0);
    glVertex2i(bs,0);
    glVertex2i(bs,-bs);
    glVertex2i(0,-bs);
    glEnd();
    glTranslated(bs,0,0);
    glColor3fv(color[color3]);
    glBegin(GL_POLYGON);
    glVertex2i(0,0);
    glVertex2i(bs,0);
    glVertex2i(bs,-bs);
    glVertex2i(0,-bs);
    glEnd();
    glTranslated(-2*bs,-bs,0);
    glColor3fv(color[color4]);
    glBegin(GL_POLYGON);
    glVertex2i(0,0);
    glVertex2i(bs,0);
    glVertex2i(bs,-bs);
    glVertex2i(0,-bs);
    glEnd();
    glPopMatrix();
glEndList();
glNewList(BOX,GL_COMPILE);
    glPushMatrix();
      .....

and randomly picking one like this

srand(time(NULL));
color1=rand()%6;
color2=rand()%6;
color3=rand()%6;
color4=rand()%6;
defineshapes();
randshape=rand()%5+1;

and drawing in display function like this

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslated(x2,y2,0);
    glCallList(randshape);
    glPopMatrix();
    glFlush();
}

I expected problem in the beginning itself when i used the display lists because i had to access the vertex values(x,y) of the shapes to check if they might overlap with another block below before moving them down. Is there a way of knowing the vertex values of objects drawn using display lists.

I encountered the same problem once before when i needed to create a tyre of a car. I wanted the tyre to be painted with colors so created a mesh by rotating a circle again using display lists. Then i needed to know the values of the intersection points of longitudes and latitudes which i didnt know how to get so i abandoned that task.

A YELL looks like this YELL

What is the easiest method of getting around this problem. I am sure OpenGL has a way of getting this done but i am new to it.

share|improve this question
1  
Forget immediate rendering mode! It's deprecated since OpenGL 3.0 and OpenGL ES 2.0. –  Miro Aug 18 '12 at 16:29
    
Sorry for my ignorance but i don't even know which version of OpenGL i have learnt. Code samples in this site often use glew.h but i have used only glut.h till now. Things like VBO are greek and latin to me. I feel like i am living in the dinosaur era. Very embarrassing. –  Mukesh Kamath Aug 18 '12 at 17:03
    
Well, that's OpenGL for you -- it's difficult to find documentation, the API is crufty and it's not easy to tell modern vs deprecated code apart at a glance. I would recommend arcsynthesis.org/gltut as one of the few places to actually learn about modern OpenGL. –  Sean Middleditch Aug 18 '12 at 22:47
    
@sean thanks for the link. Thanks everyone for the comments and answers. I just wanted to try out something different. May be learning maya or 3dsmax might help me in modelling some interesting/complex objects. –  Mukesh Kamath Aug 26 '12 at 6:07

1 Answer 1

up vote 2 down vote accepted

No, there's no way to look at the vertex data inside a display list. Even using more modern technology like VBOs or whatever, while you can look at the vertex data after you set it up, it's not necessarily a good idea to do so (it could cause performance problems if you try to look at the data while the GPU is using it).

In any case, it's not necessary. Just keep your own copy of the data in your own structures and you can look at it whenever you want. In fact, for collision detection for Tetris you don't even really want vertex data; it's much simpler if you just keep track of which grid squares are occupied or not.

share|improve this answer
    
If its not taxing you too much how will you know which blocks are occupied after rotating a TEE or YELL esp if you are not going to store vertex data(Assuming binary info stored for occupied/unoccupied). What kind of mathematics may be involved here? Can i post this as a question in the math site. –  Mukesh Kamath Aug 20 '12 at 7:08
    
@MukeshKamath You'd just have a small 2D array for each block shape that defines which grid squares it occupies, and when you rotate the block you rotate the array. Since the rotations are by 90 degrees it's easy to do this by just looping over the array elements in a different order. –  Nathan Reed Aug 20 '12 at 16:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.