www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 09455cbfe14a5607a37bf899c226b8950638ef20
parent 1851daa0aa6d55e7d3cb19133b63ef87ec4e0816
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Tue, 29 Nov 2011 12:38:29 +0100

Colors !!!

Diffstat:
Mtriangle.cpp | 3++-
Mview.cpp | 18+++++++++++-------
Mview.hh | 2++
3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/triangle.cpp b/triangle.cpp @@ -14,7 +14,8 @@ std::ostream& operator<<(std::ostream& os, const Triangle& t) { } void Triangle::display() { - glColor3ub(r, g, b); + //glColor3ub(r, g, b); + View::setColor(r,g,b); //std::cout << (int)r << "," << (int)g << "," << (int)b << std::endl; glNormal3d(normal.x,normal.y,normal.z); glBegin(GL_TRIANGLES); diff --git a/view.cpp b/view.cpp @@ -6,6 +6,10 @@ View::View(Chose* root) : root(root), cameraCenter(500,-500,100), xAngle(135), y mainLoop(); } +void View::setColor(unsigned char r, unsigned char g, unsigned char b) { + float MatDif[4] = {r/255.f, g/255.f, b/255.f, 1.0f}; + glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif); +} void View::initWindow() { SDL_Init(SDL_INIT_VIDEO); @@ -18,20 +22,20 @@ void View::initWindow() { glewInit(); float MatSpec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - float MatDif[4] = {0.0f, 0.5f, 0.0f, 1.0f}; + float MatDif[4] = {0.5f, 0.5f, 0.5f, 1.0f}; float MatAmb[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - - float Light1Pos[4] = {0.0f, 1.0f, 0.0f, 0.0f}; - float Light1Dif[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - float Light1Spec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - float Light1Amb[4] = {0.4f, 0.4f, 0.4f, 1.0f}; float shininess = 128.0f; - + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MatAmb); glMaterialfv(GL_FRONT,GL_SHININESS,&shininess); + float Light1Pos[4] = {0.0f, 1.0f, 0.0f, 0.0f}; + float Light1Dif[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + float Light1Spec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + float Light1Amb[4] = {0.4f, 0.4f, 0.4f, 1.0f}; + glLightfv(GL_LIGHT0, GL_DIFFUSE, Light1Dif); glLightfv(GL_LIGHT0, GL_SPECULAR, Light1Spec); glLightfv(GL_LIGHT0, GL_AMBIENT, Light1Amb); diff --git a/view.hh b/view.hh @@ -29,6 +29,8 @@ class View { void mainLoop(); void renderScene(); void displayAxes(); + + static void setColor(unsigned char r, unsigned char g, unsigned char b); }; #endif