Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Creating a grid

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2017
    Posts
    3

    Unhappy Creating a grid

    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.

    Code :
    void Grid::render() {
    	glPushMatrix();
    	glBegin(GL_LINES);
    	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);
    	}
    	glEnd();
    	glPopMatrix();
    }

    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!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,685
    glTranslatef is not legal between glBegin and glEnd calls. Please see the documentation:
    Errors
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2017
    Posts
    3

    Red face Done

    Okey, I solved the problem. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •