Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Cherub

color problem

This topic is 6021 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, Why both room and cube are colored, if I only did glcolor3f before cube?
  
// MainWnd.cpp: implementation of the CMainWnd class.

//

//////////////////////////////////////////////////////////////////////


#include "StdAfx.h"
#include "MainWnd.h"
#include "Numen.h"

#include <gl\glut.h>


//////////////////////////////////////////////////////////////////////

// Global Variables

//////////////////////////////////////////////////////////////////////


////// Light

float ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
float diffuseLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };	
float lightPosition[] = {-5.0,-5.0, 5.0, 0.0};	

////// Materials

float matDiff[] = { 1.0f, 1.0f, 1.0f, 1.0f};


//////////////////////////////////////////////////////////////////////

// Construction/Destruction

//////////////////////////////////////////////////////////////////////

CMainWnd::CMainWnd():
	m_hWnd(NULL),
	angle(0.0f),
	m_hRC(NULL)
{
}

CMainWnd::~CMainWnd()
{
}


void CMainWnd::drawCube(float xPos, float yPos, float zPos)
{
	glPushMatrix();	
		glColor3f(1.0, 0.0, 0.0);
		glTranslatef(xPos, yPos, zPos);
		glRotatef(angle, 1.0, 0.0, 0.0);
		glRotatef(angle, 0.0, 1.0, 0.0);
		glRotatef(angle, 0.0, 0.0, 1.0);
		glutSolidCube(4);
	glPopMatrix();
}


//

// GLCube()

// Renders a cube.

//

void CMainWnd::drawRoom(float xPos, float yPos, float zPos)
{
	glBegin(GL_QUADS);
		glNormal3f(0.0, 1.0, 0.0);
		glVertex3f(-20.0, -5.0, 10.0);
		glVertex3f( 20.0, -5.0, 10.0);
		glVertex3f( 20.0, -5.0,-20.0);
		glVertex3f(-20.0, -5.0,-20.0);
	glEnd();

	glBegin(GL_QUADS);
		glNormal3f(0.0, 0.0, 1.0);
		glVertex3f(-20.0,27.0, -20.0);
		glVertex3f( 20.0,27.0, -20.0);
		glVertex3f( 20.0,-5.0, -20.0);
		glVertex3f(-20.0,-5.0, -20.0);
	glEnd();

	glBegin(GL_QUADS);
		glNormal3f(-1.0, 0.0, 0.0);
		glVertex3f(20.0, -5.0, -20.0);
		glVertex3f(20.0, -5.0,  10.0);
		glVertex3f(20.0, 27.0,  10.0);
		glVertex3f(20.0, 27.0, -20.0);
	glEnd();

	drawCube(3.0, 5.0, 8.0);
}


//

// InitScene()

// Called when the OpenGL RC has been created. Sets the initial state for

// the OpenGL scene.

//

void CMainWnd::InitScene()
{
	glClearColor(0.0, 0.0, 0.0, 0.0);

    glEnable(GL_DEPTH_TEST);

	glEnable(GL_LIGHTING);

	glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);

    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); 

	glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
}

//

// KillScene()

// Called when the OpenGL RC is about to be destroyed. 

//

void CMainWnd::KillScene()
{
	// TODO: Use KillScene to free resources.

}

//

// DrawScene()

// Called each time the OpenGL scene has to be drawn.

//

void CMainWnd::DrawScene()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear buffers

  glLoadIdentity(); // Load identity matrix


  gluLookAt(0.0, 5.0, 25.0, 17.0, 5.0, -20.0, 0.0, 1.0, 0.0);
  
  drawRoom(0.0, 0.0, -5.0);

  glFlush();

  SwapBuffers(hDC);
}

void CMainWnd::Tick(BOOL &bRedrawScene)
{
	angle += 1;			// Add some rotation to the cube

}
  
Thanks

Share this post


Link to post
Share on other sites
Advertisement

  • 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!