Jump to content
  • Advertisement
Sign in to follow this  
lukar

OpenGL Opengl Lists

This topic is 5195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im coding a way of storing glLists for a basic showoff engine, I don't want to get into model loading yet so i made some basic code in order to store lists in a class and then load them from the renderer class to put them on screen. This is basicaly because i need to have a class that manages my objects and one that draws them, and they will be independent from one another.
//OpenGL Includes

#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "List.h"

//Class Constructor

void List::initList()
{
	base = glGenLists(30);
	glListBase(base);
	glNewList(base+1, GL_COMPILE);
			glBegin(GL_TRIANGLES);					// Start Drawing The Pyramid
	glColor3f(1.0f,0.0f,0.0f);			// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Left Of Triangle (Front)
		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Right Of Triangle (Front)
	glColor3f(1.0f,0.0f,0.0f);			// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Left Of Triangle (Right)
		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f( 1.0f,-1.0f, -1.0f);			// Right Of Triangle (Right)
glColor3f(1.0f,0.0f,0.0f);			// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f( 1.0f,-1.0f, -1.0f);			// Left Of Triangle (Back)
		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f(-1.0f,-1.0f, -1.0f);			// Right Of Triangle (Back)
	glColor3f(1.0f,0.0f,0.0f);			// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f(-1.0f,-1.0f,-1.0f);			// Left Of Triangle (Left)
		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Right Of Triangle (Left)
	glEnd();
	glEndList();
	glNewList(base+2, GL_COMPILE);
		glColor3f(4.0f,0.0f,0.0f);			// Red
		glVertex3f( 0.0f, 3.0f, 0.0f);			// Top Of Triangle (Front)
		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Left Of Triangle (Front)
		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f( 1.0f,-2.0f, 1.0f);	
	glEndList();

}

GLuint List::getListBase()
{
	return base;
}


And here is the code from where i use them
#include <gl\glu.h>
#include <gl\glaux.h>
#include "oglWrap.h"
#include "List.h"

//Class Constructor
List list;
GLfloat rot;

int Renderer::Init(GLfloat Bg[])
{
	list.initList();
	glShadeModel(GL_SMOOTH);
	glClearColor(Bg[0],Bg[1],Bg[2],Bg[3]);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	return TRUE;
}

GLvoid Renderer::Resize(GLsizei width, GLsizei height)
{
	if(height==0)
	{
		height=1;
	}
	glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int Renderer::DrawScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-3000.0f);	
	glLoadIdentity();
	glCallList(list.getListBase()+1); /////////////////////
//////////////////////////////////////////////////HERE

	
	return TRUE;
}


but apparently i cant handle them this way. Everytime i draw list.getListBase()+1 i get a screen with colors, and no matter where i translatef its the same. And list.getListBase()+2 gives me nothing... What can i do for this approach? Thank u very much for your time with this newb question ^_^

Share this post


Link to post
Share on other sites
Advertisement
The vertices in the second list are ignored as you are not drawing a primitive:

glNewList(base+2, GL_COMPILE);
glColor3f(4.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 3.0f, 0.0f); // Top Of Triangle (Front)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!