Hm. Ok.
Heres my cTexture code.
#define TEXNUM 8class cTexture{ //Tracks the enabled state. bool tracker[TEXNUM]; unsigned int texture[TEXNUM]; AUX_RGBImageRec *TexImg[TEXNUM]; public: //Sets up filename as texture num. //Returns the handle to the texture. unsigned int MakeTex(char *filename) { int i = 0; //Finds the first availible texture while(tracker[i] != false) { i++; } //checks for errors in handle if(i > TEXNUM || i < 0) { return false; } //Loads the file, checks for errors. if(!(TexImg[i] = auxDIBImageLoad(filename))) { PostQuitMessage(-1); return false; } //generate the OGL tex handle. Not my handle. glGenTextures(1,&texture[i]); //initializes the texture. glBindTexture(GL_TEXTURE_2D, texture[i]); //sets texture values. glTexImage2D(GL_TEXTURE_2D, 0, 3, TexImg[i]->sizeX, TexImg[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TexImg[i]->data); gluBuild2DMipmaps ( GL_TEXTURE_2D, 3, TexImg[i]->sizeX, TexImg[i]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TexImg[i]->data ); tracker[i] = true; return i; } //Stubbed in, will work it so that it frees up num void UnMakeTex(int num) { } //Taken from NeHe` s tutorials. int Init() { glEnable(GL_TEXTURE_2D); //This void * cast that gets multiplied by one is really weird. //I don`t know why I found it in here... memset(TexImg,0,sizeof(void *)*1); memset(tracker,false,sizeof(tracker)); //Fix MIP LOD values- done glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //I have decided that the default values for GL_TEXTURE_WRAP_S|T are satifactory. return true; } //Binds num so that the next operations use it. bool RunATex(int num) { if(num >= TEXNUM) { return false; } if (num < 0) { return false; } //Yes this tex is on if(tracker[num] == false) { return false; } glBindTexture(GL_TEXTURE_2D, texture[num]); return true; }};cTexture TEX;
Thats my cTexture class.
Here is the code I helped out with.
Its a cLight class; i didnt post my cLight because mine is very large.
As you can see, this code is more elegant,where if you want something, you declare it, instead of my monolithic approach.
#ifndef _LIGHT#define _LIGHT// light.h//// class to encapsulate the camera#include "CObject.h"#include <gl/glut.h>#define X 0#define Y 1#define Z 2typedef GLfloat vertex4D[4];typedef GLfloat vector[3];class CLight : public CObject{public: CLight(); ~CLight();//functionspublic: void SetPosition(GLfloat x, GLfloat y, GLfloat z, GLfloat point); void SetAmbient(GLfloat x, GLfloat y, GLfloat z, GLfloat a); void SetSpecular(GLfloat x, GLfloat y, GLfloat z, GLfloat a); void SetDiffuse(GLfloat x, GLfloat y, GLfloat z, GLfloat a); void Move(float x, float y, float z); void Draw(); void Position(); void Ambient(); void Specular(); void Diffuse(); void On(); void Off();protected://variablespublic: vertex4D m_Position; vertex4D m_Ambient; vertex4D m_Specular; vertex4D m_Diffuse; bool m_On; bool m_Spotlight; vector m_SpotDirection; GLfloat m_SpotExponent; GLfloat m_SpotCutoff; GLfloat m_ConstantAttenuation; GLfloat m_LinearAttenuation; GLfloat m_QuadraticAttenuation; static int number_of_lights; int m_LightID;protected:};#endif
So my question is: is there a more elegant way to structure my code ?
I came, I saw, I got programmers block.
~V'lion
[edit: changed code tags to source tags]
Edited by - Magmai Kai Holmlor on December 22, 2001 6:07:42 PM