Original Post
So i havean asteroids envionment that needs to be created and handed in in 3 weeks time. Fine if i could do anything. So I can draw stuff but basically i can't do texturing. My code is fairly long so here is the snippet i am currently working on. As you should be able to see - i am trying to texture a pyramid with a file called 'rock_texture' - which is basically just this grey gravelly thing. so here goes (NOTE: SORRY FOR THE LENGTH!) #include #include #include #pragma comment(lib,"glaux.lib") #define PI 3.1415926535898 #include #include GLuint texture[1]; #include "texture.h" #include "normal.h" float colour1[] = {0.0, 0.0, 1.0}; float colour2[] = {1.0, 0.0, 0.0}; float colour3[] = {0.0, 1.0, 0.0}; float colour4[] = {0.0, 1.0, 1.0}; float colour5[] = {1.0, 0.0, 1.0}; float colour6[] = {1.0, 1.0, 0.0}; float colour7[] = {1.0, 1.0, 1.0}; double Px, Py, Pz, roll, pitch, yaw; void initGeneral (void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ; glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); } void initLighting(void) { GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; GLfloat light[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shininess[] = {50.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat lmodel_ambient[] = {01, 0.1, 0.1, 1.0}; glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, light); glLightfv(GL_LIGHT0, GL_SPECULAR, light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void initTextures(void) { //set up and enable OpenGL Texture Mapping LoadGLTextures(0,"rock_Texture.bmp"); // load watch image (512*512) glEnable(GL_TEXTURE_2D); // enable Texture Mapping bool autoTexGen = true; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); if(autoTexGen) { glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); }else { glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } } void reshape(int w, int h) { //control the 2d viewport glViewport(0, 0, (GLsizei) w, (GLsizei) h); //control the 3d clipping volume glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-10.0, 10.0, -10.0, 10.0, 10.0, 10.0); glMatrixMode(GL_MODELVIEW); } void draw_pyramid(float size) { glBegin(GL_TRIANGLES); glColor3fv(colour1); glVertex3f(0.0*size, 0.2*size, 0.0*size); glVertex3f(-0.2*size, 0.45*size, -0.1*size); glColor3fv(colour2); glVertex3f(0.0*size, 0.2*size, 0.0*size); glVertex3f(0.0*size, 0.2*size, -0.2*size); glVertex3f(-0.2*size, 0.45*size, -0.1*size); glColor3fv(colour3); glVertex3f(0.0*size, 0.2*size, -0.2*size); glVertex3f(-0.4*size, 0.2*size, -0.2*size); glVertex3f(-0.2*size, 0.45*size, -0.1*size); glColor3fv(colour4); glVertex3f(-0.4*size, 0.2*size, -0.2*size); glVertex3f(-0.4*size, 0.2*size, 0.0*size); glVertex3f(-0.2*size, 0.45*size, -0.1*size); glEnd(); glBegin(GL_QUADS); glColor3fv(colour5); glVertex3f(-0.4*size, 0.2*size, 0.0*size); glVertex3f(-0.0*size, 0.2*size, 0.0*size); glVertex3f(-0.0*size, 0.2*size, -0.2*size); glVertex3f(-0.4*size, 0.2*size, -0.2*size); glEnd(); } void keys(unsigned char key, int x, int y) { switch(key) { case 'd': Px -= 0.1; break; case 'a': Px += 0.1; break; case 'w': Py -= 0.1; break; case 's': Py += 0.1; break; case 'p': pitch += 1.0; break; case 'r': roll += 1.0; break; case 'y': yaw += 1.0; break; } glutPostRedisplay(); glLoadIdentity(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); //clear colour buffer to black glRotated(roll, 0, 0, 1); glRotated(pitch, 1, 0, 0); glRotated(yaw, 0, 1, 0); glTranslated(-Px, -Py, -Pz); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, texture[0]); draw_pyramid(1.0); glutSwapBuffers(); // update screen } int main(int argc, char** argv) { glutInit (&argc, argv) ; glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ; glutInitWindowSize (400, 400) ; glutInitWindowPosition (500, 500) ; glutCreateWindow ("example1") ; glutKeyboardFunc(keys); initGeneral(); //initialise general settings // initLighting(); //initialise opengl lighting initTextures(); glutDisplayFunc (display) ; //set up call back for display glutMainLoop () ; return 0 ; } I will do another post below quickly to show you the texture.h file so you can see everything thats going into this project and hopefully help me out. Basically i can't see anything on ym screen any more except fro blackness!