Thread: Opengl Displaylist

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Opengl Displaylist

    Hi, im trying to make a DisplayList in Opengl (glut)

    This is the box (WallPiece) , that is calling to the _displayListId
    Code:
    void build(){
    	glMatrixMode(GL_MODELVIEW);
    	glColor3f(1.0f, 1.0f, 1.0f);
    	glEnable(GL_TEXTURE_2D);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glLoadIdentity();
    		glBegin(GL_QUADS);
    			glTexCoord2f(0.0f, 1.0f);
    			glVertex2f(0, 0);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex2f(0.1, 0);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex2f(0.1, 0.1);
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex2f(0, 0.1);
    		glEnd();
    		glDisable(GL_TEXTURE_2D);
    }
    This is inside the initRendering()
    Code:
    	_displayListId = glGenLists(1);
    	glNewList(_displayListId, GL_COMPILE);
    	build();
    	glEndList();
    And this should display it
    Code:
    void drawScene() {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glPushMatrix();
    	glBindTexture(GL_TEXTURE_2D, _wall2);
    	for(xloop = -1; xloop<3; xloop++){
    		glTranslatef(xloop, yloop, -3);
    		glCallList(_displayListId);
    	}
    	glPopMatrix();
    	glutSwapBuffers();
    }
    I want it to be a long wall, my code kinda works, i get many of my WallPiece in a row, but all of them are in different scales, brobably on the Z-axis.

    Can anyone tell me what i have missed, or whats wrong?

    //ty in advace

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
    	for(xloop = -1; xloop<3; xloop++){
    		glTranslatef(xloop, yloop, -3);
    		glCallList(_displayListId);
    	}
    Every time you call glTranslatef, the translation is added to the previous translation so lets say you start on (0,0,0), the 1st time you call glTranslatef, you'll translate (-1, yloop, -3) which will bring you to (-1, yloop, -3), the second time, you'll end up in (-2, 2*yloop, -6), etc

    I'd suggest against using identifiers starting with an underscore as those are reserved
    Last edited by h_howee; 03-08-2008 at 12:45 PM.

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM