Thirthe

Members
  • Content count

    52
  • Joined

  • Last visited

Community Reputation

128 Neutral

About Thirthe

  • Rank
    Member
  1. MD2 loader

    davek20: If you will decide to visit Central Europe, please find me so that I can kiss you :D Thanks!
  2. MD2 loader

    So I wanted to make an MD2 loader... Well, I started off easy, by loading only the 1st frame using those horrid glBegin()/glEnd() functions. And it worked! I could load the Q2 models nicely. But then I wanted to render the models with VA (and then later on, VBO) method and now I'm seeing incomplete or corrupted models rendered on the screen. But, I should say, the MD2 models that were actually quite primitive (pyramids, cubes, hex prisms...) I had no problem rendering correctly. screenshot: http://i34.tinypic.com/2vudi7n.jpg code: index_num = model->header->num_tris * 3; vertex_num = model->header->num_vertices * 3; indices = new GLubyte[ index_num ]; vertices = new GLfloat[ vertex_num ]; vertices_original = new GLfloat[ vertex_num ]; color = new GLfloat[ vertex_num ]; int j; for( int i = 0, j = 0; i < model->header->num_tris; ++i ) { indices[j++] = model->triangle[i].vertexIndices[0]; indices[j++] = model->triangle[i].vertexIndices[1]; indices[j++] = model->triangle[i].vertexIndices[2]; } // TODO: remember, there can be more than 1 frame for( int i = 0, j = 0; i < model->header->num_vertices; ++i ) { vertices_original[j++] = (model->frame[0].vertices[i].vertex[0] * model->frame[0].scale[0]) + model->frame[0].translate[0]; vertices_original[j++] = (model->frame[0].vertices[i].vertex[1] * model->frame[0].scale[1]) + model->frame[0].translate[1]; vertices_original[j++] = (model->frame[0].vertices[i].vertex[2] * model->frame[0].scale[2]) + model->frame[0].translate[2]; } mode_primitive = GL_TRIANGLES; coords[0] = x; // user-defined origin coords coords[1] = y; coords[2] = z; rendering: for( unsigned int i = 0U; i <= vertex_num - 3; i += 3 ) { vertices[i] = coords[0] + vertices_original[i]; vertices[i+1U] = coords[1] + vertices_original[i+1U]; vertices[i+2U] = coords[2] + vertices_original[i+2U]; } glEnableClientState( GL_COLOR_ARRAY ); glEnableClientState( GL_VERTEX_ARRAY ); glColorPointer( 3, GL_FLOAT, 0, color ); glVertexPointer( 3, GL_FLOAT, 0, vertices ); glDrawElements( mode_primitive, index_num, GL_UNSIGNED_BYTE, indices ); glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_COLOR_ARRAY ); NOTE: 'vertices_original' stores model's vertices on the local coordinate system 'vertices' stores model's vertices on the global (world) coordinate system and 'coords' are the model's origin coords of the global (world) coordinate system so basically coords + vertices_original positions the object into the world. P.S.: I'm kind of new to 3D, so I'm not sure if I used the phrases correctly :) [Edited by - Thirthe on September 2, 2008 7:11:13 AM]
  3. ABC and not found methods in derived classes

    i see. i should refresh my knowledge of polymorphism now thanks!
  4. Hey. I have an ABC 'Object3D' and one derived class 'MobileObject3D' with an extra public method 'setAcceleration' that isn't defined in the ABC. Because of this i'm getting the following error: ".cpp|69|error: 'class Object3D' has no member named 'setAcceleration'|" I thought i was able access the public methods of the derived classes, but it seems i cannot.. why is that? Isn't polymorphism similar to inheritance? Object3D.h class Object3D { public: Object3D( const unsigned int quad_num ); virtual ~Object3D(); virtual void BuildRectSolid( const Vertex3 origin, const float width, const float height, const float depth, const unsigned char color_id ) = 0; virtual void Build() = 0; virtual void Render() = 0; Mesh *mesh; protected: GLint DL; // DL GLfloat *vertices; // VA GLubyte *indices; // VA GLfloat *color; // VA }; MobileObject3D.h class MobileObject3D : public Object3D { public: MobileObject3D( const unsigned int quad_num ); ~MobileObject3D(); void setAcceleration( const GLfloat accel ); void BuildRectSolid( const Vertex3 origin, const float width, const float height, const float depth, const unsigned char color_id ); //void Move(); void Build(); void Render(); Vertex3 coords; GLfloat w, h, d; GLfloat acceleration; private: void NextFrame(); }; main.cpp // test mobile cube cube = new MobileObject3D( 0 ); cube->setAcceleration( 0.2 ); cube->BuildRectSolid( tmp, 10, 10, 10, 1 ); ty
  5. they will be called later in program
  6. Hello, gamedev! So, I have this class... class Object { public: void setObject( const float w, const float h ); private: float width, height; }; void Object::setObject( const float w, const float h ) { width = w; height = h; // from now on, what should i use? w/h or width/height? // is one or the other accessed faster? } thank you.
  7. Hello all! I've just went through the 8th NeHe's lesson(blending) and it seems that when I change the alpha values in glColor4f() funct, nothing changes the scene! I have fiddled around with different blending functions and sorted the polys from farthest to nearest, but still nothing changes the transparency of the (two) polys in the scene. I have a gf2mx, the latest glext.h and the latest drivers installed. Also, glGetError() reports that there were no errors. relevant functions: void init( char *a ) { glClearColor( 0.6f, 0.8f, 0.2f, 0.0f ); glShadeModel( GL_SMOOTH ); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); init_VBO(); load_tex( a ); init_light(); } void init_light() { GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 10.0 }; GLfloat white_light[] = { 1.0, 1.0, 0.5, 1.0 }; GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { -6.0, 7.0, 6.0, 1.0 }; glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); glLightfv(GL_LIGHT0, GL_POSITION, light_position); //glLightfv(GL_LIGHT0, GL_AMBIENT, white_light); //similar? glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient ); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); } static void display(void) { glMatrixMode( GL_MODELVIEW ); // do NOT switch MatrixMode every frame! glLoadIdentity(); // do NOT loadidentity ever frame (use push/popmatrix instead) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindBuffer( GL_ARRAY_BUFFER, VBO ); glBindTexture( GL_TEXTURE_2D, tex[tex_id] ); glVertexPointer( 3, GL_FLOAT, sizeof(GLfloat)*5, BUFFER_OFFSET(0) ); // Set The Vertex Pointer To The Vertex Buffer glTexCoordPointer( 2, GL_FLOAT, sizeof(GLfloat)*5, BUFFER_OFFSET( sizeof(GLfloat)*3 ) ); glColor3f( 1.f, 1.f, 1.f ); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable (GL_TEXTURE_2D); glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glDrawArrays( GL_QUADS, 0, 4 ); // 4 == vertex count glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); glDisable (GL_TEXTURE_2D); //glDisable(GL_DEPTH_TEST); glEnable( GL_BLEND ); glTranslatef( 0.f, 2.f, 0.f ); glColor4f( 1.f, 0.f, 1.f, 1.0f ); glutSolidCube( 4.0 ); glColor4f( 0.f, 0.f, 1.f, 1.0f ); glBegin(GL_QUADS); // quick trick: 1.f(normal) is where the column of numbers(vertex) are the same! glNormal3f( 0.f, 1.f, 0.f ); glVertex3f( 4.0f, 4.0f,-4.0f); // Top Right Of The Quad (Top) glVertex3f(-4.0f, 4.0f,-4.0f); // Top Left Of The Quad (Top) glVertex3f(-4.0f, 4.0f, 4.0f); // Bottom Left Of The Quad (Top) glVertex3f( 4.0f, 4.0f, 4.0f); // Bottom Right Of The Quad (Top) glNormal3f( 0.f, -1.f, 0.f ); glVertex3f( 4.0f,-4.0f, 4.0f); // Top Right Of The Quad (Bottom) glVertex3f(-4.0f,-4.0f, 4.0f); // Top Left Of The Quad (Bottom) glVertex3f(-4.0f,-4.0f,-4.0f); // Bottom Left Of The Quad (Bottom) glVertex3f( 4.0f,-4.0f,-4.0f); // Bottom Right Of The Quad (Bottom) glNormal3f( 0.f, 0.f, 1.f ); glVertex3f( 4.0f, 4.0f, 4.0f); // Top Right Of The Quad (Front) glVertex3f(-4.0f, 4.0f, 4.0f); // Top Left Of The Quad (Front) glVertex3f(-4.0f,-4.0f, 4.0f); // Bottom Left Of The Quad (Front) glVertex3f( 4.0f,-4.0f, 4.0f); // Bottom Right Of The Quad (Front) glNormal3f( 0.f, 0.f, -1.f ); glVertex3f( 4.0f,-4.0f,-4.0f); // Top Right Of The Quad (Back) glVertex3f(-4.0f,-4.0f,-4.0f); // Top Left Of The Quad (Back) glVertex3f(-4.0f, 4.0f,-4.0f); // Bottom Left Of The Quad (Back) glVertex3f( 4.0f, 4.0f,-4.0f); // Bottom Right Of The Quad (Back) glNormal3f( -1.f, 0.f, 0.f ); glVertex3f(-4.0f, 4.0f, 4.0f); // Top Right Of The Quad (Left) glVertex3f(-4.0f, 4.0f,-4.0f); // Top Left Of The Quad (Left) glVertex3f(-4.0f,-4.0f,-4.0f); // Bottom Left Of The Quad (Left) glVertex3f(-4.0f,-4.0f, 4.0f); // Bottom Right Of The Quad (Left) glNormal3f( 1.f, 0.f, 0.f ); glVertex3f( 4.0f, 4.0f,-4.0f); // Top Right Of The Quad (Right) glVertex3f( 4.0f, 4.0f, 4.0f); // Top Left Of The Quad (Right) glVertex3f( 4.0f,-4.0f, 4.0f); // Bottom Left Of The Quad (Right) glVertex3f( 4.0f,-4.0f,-4.0f); // Bottom Right Of The Quad (Right) glEnd(); // Done Drawing The Pyramid glDisable( GL_BLEND ); //glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glutSwapBuffers(); } btw, with this code, even with alpha values set to 1.0f in glColor4f(), it makes the two polys transparent. Thank you!
  8. beginner rotation/translation problem

    This was exactly what I've meant, thanks! :)
  9. beginner rotation/translation problem

    thank you all for help. the sequence i used was Identity*R*T and it worked. i still wonder about the performance questions, though: 1.) do i really need to call glFlush() in this case? 2.) should i call glEnable() and glDisable() when needed OR should i call glEnable() in the beginning of the program and glDisable() when cleaning up?
  10. hello all, i have a problem with the most basic stuff and i feel terrible. i am trying to recreate, in my own special way, NeHe's 11th lesson, where i can walk through a simple 3D world. so far i have a large 100*100 plane(on x,z axis') and i can walk forward/backward nicely. if i turn in origin point, the camera rotates nicely and i can walk forward and backward nicely, as well(basic trig). but the problem arises, when i go forward a little and then try to turn. instead that the camera would rotate in-place it warps(translates) to another location. first i tried with loading the identity matrix, rotating the camera to the stored angle and then translating her to the stored position, but that did not work(i suspect my resize() funct. and yes, i did translate first and rotate second.), so i just rotate and translate on-the-fly or step by step. i also tried putting glRotate(), in the key() funct where case 'a' and case 'd' evaluates, between glPushMatrix() and glPopMatrix(), but then nothing happens... why not? anyway, my code: // NOTE: i used the cur_* vars, when i tried translating/rotation objects from the origin point(identity matrix). they're kinda obsolete atm, but i've left them in anyway. GLfloat cur_x = 0.f; const GLfloat cur_y = -1.f; GLfloat cur_z = 0.f; GLfloat angle = 90.f; GLfloat step_x = 0.f; GLfloat step_z = 0.f; // // GLUT callback Handlers // static void idle(void) { glutPostRedisplay(); } static void key( const unsigned char key, const int x, const int y ) { glMatrixMode( GL_PROJECTION ); switch (key) { case 27 : case 'q': deinit(); break; case 'w': // move forward step_x = cosf( angle * (M_PI/180.f) ) * 1.f; step_z = sinf( angle * (M_PI/180.f) ) * 1.f; cur_x += step_x; cur_z += step_z; glTranslatef( step_x, 0.f, step_z ); break; case 's': // move backward step_x = cosf( angle * (M_PI/180.f) ) * -1.f; step_z = sinf( angle * (M_PI/180.f) ) * -1.f; cur_x += step_x; cur_z += step_z; glTranslatef( step_x, 0.f, step_z ); break; case 'd': // turn right if( (angle += 5.f) > 360.f ) angle = 0.f; glRotatef( 5, 0.f, 1.f, 0.f ); break; case 'a': // turn left if( (angle -= 5.f) < 0.f ) angle = 360.f; glRotatef( 5, 0.f, -1.f, 0.f ); break; } glutPostRedisplay(); } static void resize( const int width, const int height ) { const GLdouble ar = (GLdouble)width / (GLdouble)height; glViewport(0, 0, (GLsizei)width, (GLsizei)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( -ar, ar, -1.0, 1.0, 1.0, 169.0 ); glTranslatef( cur_x, cur_y, cur_z ); // (0, -1, 0) // NOTE: i call MODELVIEW in the beginning of the display() funct } static void display(void) { glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList( DL ); // the 100*100 plane glutSwapBuffers(); glFlush(); } /* Program entry point */ int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("Walk"); glutReshapeFunc(resize); glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(idle); init(); glutMainLoop(); return EXIT_SUCCESS; } also, two side-questions: 1.) do i really need to call glFlush() in this case? 2.) should i call glEnable() and glDisable() when needed OR should i call glEnable() in the beginning of the program and glDisable() when cleaning up? thanks! [Edited by - Thirthe on June 24, 2008 4:41:35 PM]
  11. heh, i see this is a problem that often occurs often with us newbies. anyway, the problem was solved by downloading the newest glext.h and putting this into the code: PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements = NULL; glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)wglGetProcAddress("glDrawRangeElements"); thanks!
  12. Hello all, i'm starting with OpenGL, so i got the red book 5th ed. and now i'm going through it, page by page. So, the first problem is that the 5th ed. includes the 1.5/2.0 features, while i'm programming in OpenGL 1.3. But so far i was good, since it said for which version a specific function was implemented. But i'm pretty sure i can use glDrawRangeElements(): "glDrawRangeElements is available only if the GL version is 1.2 or greater." i'm using winxp, Code::Blocks and compiling with mingw g++-3.4.5 also, i followed http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/glut/ for setting up OpenGL. my main.cpp file: #ifdef __cplusplus extern "C" { #endif #include <windows.h> #include <GL/glut.h> #include <stdlib.h> #ifdef __cplusplus } #endif void display(void) { glClear (GL_COLOR_BUFFER_BIT); static GLfloat lol[] = { 1.0, 1.0, 0.0, -0.5, 0.25, 1.0, 1.0, 1.0, -0.50f, 0.f, 1.0, 0.0, 0.0, 0.50f, -0.25f, 0.0, 0.0, 0.0, 0.50f, 0.25f }; glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); glColorPointer( 3, GL_FLOAT, 5*sizeof(GLfloat), &lol[0] ); glVertexPointer( 2, GL_FLOAT, 5*sizeof(GLfloat), &lol[3] ); static GLuint in[] = {0,1,2,3}; //glDrawElements( GL_POLYGON, 4, GL_UNSIGNED_INT, in ); glDrawRangeElements( GL_POLYGON, 0, 3, 4, GL_UNSIGNED_INT, in); //glBegin(GL_POLYGON); // for( int i = 0; i < 4; ++i ) // glArrayElement(i); //glEnd(); //glDisable( GL_POLYGON_STIPPLE ); glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_COLOR_ARRAY ); glFlush (); } Btw, is there a way of getting a newer OpenGL API for mingw gcc? Thanks!
  13. [C/C++] recommended branching in functions?

    Quote:Original post by murdock I would also recommend that you use only one return statement in a function. why is that?
  14. [C/C++] recommended branching in functions?

    thank you all for commenting, i understand the problem much clearer now!
  15. Hello all! I'm wondering what is the better way of programming (in the sense of readability, performance, code generation...) the type of functions that do out-of-bound checking and must exit, if the data is indeed out-of-bound: #1 int getElement( const unsigned int id ){ if( id < 0 || id > max_elements ) return SOME_ERROR_NO; return array[id]; } or #2 int getElement( const unsigned int id ){ if( id >= 0 && id < max_elements ) return array[id]; return SOME_ERROR_NO; } Note: I don't have a specific problem, but I was often wondering what way I should code in the future.. Thank you!