View Full Version : Creating a grid

06-07-2017, 08:49 AM
Hi, I am doing a student project and I am doing a little "game" in Visual Studio with C++. I would like to create a grid surface up and down a spaceship. I tried the code below and it works.

void Grid::render() {
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(100.0f, 100.0f, 100.0f);
for (int i = -size; i <= size; i++)
glVertex3f((float)i, 0, (float)-size);
glVertex3f((float)i, 0, (float)size);

glVertex3f((float)-size, 0, (float)i);
glVertex3f((float)size, 0, (float)i);

I would like to move the grid. Modify the grid position, but I don't know how. What instruction should I use and how? I tried to upload a picture in case I haven't explained myself properly, but for some reason I can't do it. I expect I have explained correctly.

Thanks in advance!

06-07-2017, 09:17 AM
glTranslatef is not legal between glBegin and glEnd calls. Please see the documentation (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml):
GL_INVALID_OPERATION is generated if glTranslate is executed between the execution of glBegin and the corresponding execution of glEnd.Fix that and you will find that, using old-style OpenGL as you are, glTranslatef is one appropriate way of moving the grid.

06-07-2017, 10:11 AM
Okey, I solved the problem. Thank you!