Jump to content
  • Advertisement

RichRoberts

Member
  • Content Count

    5
  • Joined

  • Last visited

Everything posted by RichRoberts

  1. im trying to add another texture into my scene everything ok apart from the start when i go to compile i get error C2374: 'texName' : redefinition; multiple initialization, but when i change it to texName 2 it crashes on me, below is a sample of the code im having an issue with #define FLOOR 0 #define DOOR 1 struct Image { unsigned long size_x; unsigned long size_y; char *data; }; typedef struct Image Image; const int texNum = 2; Image texData[texNum]; GLuint theTexture[texNum]; char* texName[texNum] = {"floor.bmp"}; char* texName[texNum] = {"door.bmp"};
  2. RichRoberts

    fps camera

    im trying to get a "camera" working so that it can go through my 3d level ive got it to compile with no issues but the camera doesnt move at all when i press a key, can anyone see where ive gone wrong void keyboard (unsigned char key, int x, int y) { if (key=='q') { xrot += 1; if (xrot >360) xrot -= 360; } if (key=='z') { xrot -= 1; if (xrot < -360) xrot += 360; } if (key=='w') { float xrotrad, yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xrotrad = (xrot / 180 * 3.141592654f); xpos += float(sin(yrotrad)) ; zpos -= float(cos(yrotrad)) ; ypos -= float(sin(xrotrad)) ; } if (key=='s') { float xrotrad, yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xrotrad = (xrot / 180 * 3.141592654f); xpos -= float(sin(yrotrad)); zpos += float(cos(yrotrad)) ; ypos += float(sin(xrotrad)); } if (key=='d') { yrot += 1; if (yrot >360) yrot -= 360; } if (key=='a') { yrot -= 1; if (yrot < -360)yrot += 360; } if (key==27) { exit(0); } } void mouseMovement(int x, int y) { int diffx=x-lastx; int diffy=y-lasty; lastx=x; lasty=y; xrot += (float) diffy; yrot += (float) diffx; }
  3. RichRoberts

    Door animation

    Im trying to animate a door so that if i press a button the door will open, at the moment it compiles and when i go to press the button it moves the camera and then i cant control the camera anymore, so i dont know what is wrong with the code, any help would be great glPushMatrix; glTranslatef (door_Xpos,0.0, 0.0); glRotatef (door_Angle, 1,0,0); glBegin(GL_QUADS); //door left glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(0.0, 15.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(0.0, 0.0, -25.0); //door right glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(0.0, 15.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(0.0, 0.0, -25.0); glPopMatrix; void keyboard(unsigned char key, int x, int y) { switch (key) { case 'a': case 'A': glTranslatef(5.0, 0.0, 0.0); break; case 'd': case 'D': glTranslatef(-5.0, 0.0, 0.0); break; case 'w': case 'W': glTranslatef(0.0, 0.0, 5.0); break; case 's': case 'S': glTranslatef(0.0, 0.0, -5.0); break; case 't': case 'T': if (is_depth) { is_depth = 0; glDisable(GL_DEPTH_TEST); } else { is_depth = 1; glEnable(GL_DEPTH_TEST); } case 'o': case 'O': door_Xpos += 90.0; break; } display(); }
  4. RichRoberts

    texture function problems

    thanks for that bit but its still crashing and im wondering if it has to do with this part of the code for(int k=0; k < texNum; k++) { if(!GLloader(texName[k], &texData[k])) exit(1); glGenTextures(2, &theTexture[k]); glBindTexture(GL_TEXTURE_2D, theTexture[k]); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texData[k].size_x, texData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, texData[0].data); } for(int d=0; d < texNum; d++) { if(!GLloader(texName[d], &texData[d])) exit(1); glGenTextures(2, &theTexture[d]); glBindTexture(GL_TEXTURE_2D, theTexture[d]); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texData[d].size_x, texData[d].size_y, GL_RGB, GL_UNSIGNED_BYTE, texData[d].data); } }
  5. RichRoberts

    Door animation

    this is my whole code if that helps, iwhere should the gltranslate and glrotate functions go then, thanks #include <windows.h> #include <gl\gl.h> #include <gl\glut.h> #include <gl\glu.h> #include <stdio.h> #include <iostream> void init(void); void display(void); void keyboard(unsigned char, int, int); void resize(int, int); GLfloat door_Xpos; GLfloat door_Angle; GLint camposz; int is_depth; int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(600, 600); glutInitWindowPosition(40, 40); glutCreateWindow("Underground cave"); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(resize); glutMainLoop(); return 0; } void init(void) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); is_depth = 1; glMatrixMode(GL_MODELVIEW); } void display(void) { if (is_depth) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); else glClear(GL_COLOR_BUFFER_BIT); GLfloat lightColor0[] = {0.2f, 0.2f, 0.2f, 1.0f}; GLfloat lightPos0[] = {50.0f, 0.0f, 50.0f, 1.0f}; glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); GLfloat lightColor1[] = {0.2f, 0.2f, 0.2f, 1.0f}; GLfloat lightPos1[] = {50.0f, 0.0f, -400.0f, 1.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); glPushMatrix; glTranslatef(door_Xpos,0.0, 0.0); glRotatef(door_Angle, 1,0,0); glBegin(GL_QUADS); //door left glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-10.0, 15.0, -15.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-10.0, 0.0, -15.0); //door right glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(0.0, 15.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(0.0, 0.0, -25.0); glPopMatrix; //floor glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 0.0, 25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 0.0, 25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 0.0, -25.0); //left wall glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 00.0, 25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 25.0, 25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 25.0, -25.0); //right wall glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(50.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(50.0, 00.0, 25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 25.0, 25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 25.0, -25.0); //roof glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 25.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 25.0, 25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 25.0, 25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 25.0, -25.0); //right panel glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 15.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 0.0, -25.0); //left panel glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 15.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 15.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 0.0, -25.0); //top panel glColor3f(0.2f, 0.2f, 0.2f); //bottom right glVertex3f(50.0, 15.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); //top right glVertex3f(50.0, 25.0, -25.0); glColor3f(0.6f, 0.6f, 0.6f); //top left glVertex3f(-50.0, 25.0, -25.0); glColor3f(0.8f, 0.8f, 0.8f); //bottom left glVertex3f(-50.0, 15.0, -25.0); // corridor floor glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 0.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(10.0, 0.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(10.0, 0.0, -25.0); // corridor left wall glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 00.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-10.0, 15.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-10.0, 15.0, -25.0); // corridor right wall glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(10.0, 0.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(10.0, 00.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(10.0, 15.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(10.0, 15.0, -25.0); //corridor roof glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 15.0, -25.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 15.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(10.0, 15.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(10.0, 15.0, -25.0); //right panel room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(10.0, 0.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(10.0, 15.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 15.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 0.0, -275.0); //left panel room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-10.0, 0.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-10.0, 15.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 15.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 0.0, -275.0); //top panel room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(50.0, 15.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(50.0, 25.0, -275.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 25.0, -275.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 15.0, -275.0); //right wall room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(50.0, 0.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(50.0, 00.0, -325.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 25.0, -325.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 25.0, -275.0); //left wall room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 0.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 00.0, -325.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 25.0, -325.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 25.0, -275.0); //roof room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 25.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 25.0, -325.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 25.0, -325.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 25.0, -275.0); //back wall room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(50.0, 0.0, -325.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(50.0, 25.0, -325.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(-50.0, 25.0, -325.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(-50.0, 0.0, -325.0); //floor room 2 glColor3f(0.2f, 0.2f, 0.2f); glVertex3f(-50.0, 0.0, -275.0); glColor3f(0.4f, 0.4f, 0.4f); glVertex3f(-50.0, 0.0, -325.0); glColor3f(0.6f, 0.6f, 0.6f); glVertex3f(50.0, 0.0, -325.0); glColor3f(0.8f, 0.8f, 0.8f); glVertex3f(50.0, 0.0, -275.0); glEnd(); glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 'a': case 'A': if(camposz < 50) { glTranslatef(5.0, 0.0, 0.0); camposz= camposz+5; } break; case 'd': case 'D': glTranslatef(-5.0, 0.0, 0.0); break; case 'w': case 'W': glTranslatef(0.0, 0.0, 5.0); break; case 's': case 'S': glTranslatef(0.0, 0.0, -5.0); break; case 't': case 'T': if (is_depth) { is_depth = 0; glDisable(GL_DEPTH_TEST); } else { is_depth = 1; glEnable(GL_DEPTH_TEST); } break; case 'o': case 'O': door_Xpos += 90.0; break; } display(); } void resize(int width, int height) { if (height == 0) height = 1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* note we divide our width by our height to get the aspect ratio */ gluPerspective(45.0, width / height, 1.0, 400.0); /* set initial position */ glTranslatef(0.0, -5.0, -10.0); glMatrixMode(GL_MODELVIEW); }
  • 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!