Keermalec

Members
  • Content count

    183
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Keermalec

  • Rank
    Member
  1. qsort - what am I doing wrong? (code included)

    ??? The edit button is gone, so here's the image: As you can see, one of the back triangles is not being rendered as it should, and when the camera moves around, triangles switch from back to front of each other, which clearly means they are not being sorted right.
  2. Hi, I am trying to sort from back to front because of several transparent surfaces, but I geet this: [IMG]http://www.christov.com/ogl/qsort.jpg[/IMG] here is the code: [SOURCE] struct MCtri { int vi[3]; // Vertex index float dist; // Distance from camera }; struct MCscene { int numVert; // Number of verts float *vert[3]; // Vertices int numTri; // Number of triangles MCtri *tri; // Trianges float camPos[3]; // Camera position }; // Compare function int mcCompare(struct MCtri *elem1, struct MCtri *elem2) { if ( elem1->dist < elem2->dist) // If First Structure distance Is Less Than The Second return -1; // Return -1 else if (elem1->dist > elem2->dist) // If First Structure distance Is Greater Than The Second return 1; // Return 1 else // Otherwise (If The distance Is Equal) return 0; // Return 0 } // Calculate distance between two points in 3d float mcDistance3d(float[3] ptA, float[3] ptB) { float tempa = ptA[MC_X] - ptB[MC_X]; float tempb = ptA[MC_Y] - ptB[MC_Y]; float tempc = ptA[MC_Z] - ptB[MC_Z]; return sqrt((tempa*tempa)+(tempb*tempb)+(tempc*tempc)); } // Returns the smallest of a group of three numbers (same as min() found in <algorithm>) float mcSmallest (float A, float B, float C) { float smallest; if (A <= B) { if (A <= C) smallest = A; else smallest = C; } else if (B <= C) smallest = B; else smallest = C; return smallest; } void mcMeasureTriDist( MCscene *s ) { MCuint32 mc_t; float dist[3]; for ( mc_t = 0; mc_t < s->numTri; mc_t++ ) { dist[0] = mcDistance3d( s->camPos, s->tri[mc_t].vi[0]]); dist[1] = mcDistance3d( s->camPos, s->tri[mc_t].vi[1]]); dist[2] = mcDistance3d( s->camPos, s->tri[mc_t].vi[2]]); s->tri[mc_t].dist = mcSmallest( dist[0], dist[1], dist[2] ); } } void mcRender( MCscene *s ) { // Measure distance to camera for each triangle mcMeasureTriDist(s); // Sort triangles from back to front qsort((void *) s->tri, s->numTri, sizeof(struct MCtri), (compfn)mcCompare ); // Render each triangle for ( mc_t = 0; mc_t < s->numTri; mc_t++) { glBegin(GL_TRIANGLES); glVertex3fv( s->tri[mc_t].vi[0]] ); glVertex3fv( s->tri[mc_t].vi[1]] ); glVertex3fv( s->tri[mc_t].vi[2]] ); glEnd(); } } [/SOURCE] Thanks for your thoughts, Keer:-)
  3. opengl error message?

    Hi, a friend of mine tries to run my opengl app and gets the following error message on Win XP SP2. he has a GefOrce 460 with latest (v71.84) drivers from nvidia. Any ideas what it could mean? AppName: marble with lightmaps 0.2m.exe AppVer: 0.0.0.0 ModName: marble with lightmaps 0.2m.exe ModVer: 0.0.0.0 Offset: 0000635e many thanks, keer
  4. Second rendering window as transparent overlay

    That worked! Thanks Ivllatrix, Keer
  5. Second rendering window as transparent overlay

    Sheesh, I was only expecting an answer...
  6. Hi, I would like to acheive the effect drawn below: a second rendering window, smaller than the first, to be overlaid semi-transparently over the first. Its use would be for example to look behind the user in a first person shooter. Any suggestions on how this can be done?
  7. How to program a chess: a forum based tutorial

    Following Ivllatrix's logic, we could model our chess pieces this way: // A triangle is composed of 3 vertices struct mdl_triangle { unsigned int vert_index[3]; // Vertex Index numbers }; // A chess piece is all one colour and is composed of triangles struct mdl_piece { unsigned char col[3]; // Material colour unsigned long int num_tri; // Number of triangles mdl_triangle *tri; // Triangles unsigned long int num_vert; // Number of vertices float *vert[3]; // Vertices }; // A game set is composed of 32 chess pieces struct mdl_game { mdl_piece *piece; // Chess pieces };
  8. How to program a chess: a forum based tutorial

    Without meaning to question the excellent work you are doing Ivllatrix, why not just focus on the game by making the windows creation/management code as simple as possible for the time being; for example by using GLUT or SDL? For a simple project like this it seems better to develope the gaming code first and concentrate later on the interface code. It may also be less confusing for a beginner. For example, here is the chess board in just 80 lines of code using glut: // Basic 60-line Glut code from http://personal.nbnet.nb.ca/daveg/opengl/misc/#PicoCube #include <GL/glut.h> void reshapeFunc( int w, int h ) { glViewport( 0, 0, w, h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if( h < 1 ) h = 1; gluPerspective( 30.0, (double)w / (double)h, 1.0, 1000.0 ); glMatrixMode( GL_MODELVIEW ); } void draw_board(void) { int x, z; for (x = 0; x < 8; x++) { for (z = 0; z < 8; z++) { float col = (float)((x % 2) ^ (z % 2)); glColor3f(col, col, col); glPushMatrix(); glTranslatef((float)(2*x), 0, (float)(2*z)); glBegin(GL_QUADS); glVertex3f(-1.0f, 0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, 1.0f); glVertex3f( 1.0f, 0.0f,-1.0f); glVertex3f(-1.0f, 0.0f,-1.0f); glEnd(); glPopMatrix(); } } } void displayFunc(void) { static GLfloat angle1 = 0.0f; angle1 += 1.0f; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); // Cancels all transformations gluLookAt( 20.0f, 15.0f, 20.0f, // Camera position 0.0f, 0.0f, 0.0f, // Camera direction 0, 1, 0 ); // Camera up vector glPushMatrix(); // Objects rendered between push and popMatrix will be transformed without affecting camera glRotatef( angle1, 0.0f, 1.0f, 0.0f ); // Rotates objects which follow glTranslatef( -7.0, 0.0, -7.0 ); // Centers board on coords 0,0,0 draw_board(); glPopMatrix(); // Objects rendered between push and popMatrix will be transformed without affecting camera glutSwapBuffers(); glutPostRedisplay(); } void keyboardFunc( unsigned char key, int x, int y ) { switch( key ) { case 27: // ESC key glutDestroyWindow( glutGetWindow() ); exit( 0 ); } } int main( int argc, char* argv[] ) { glutInit( &argc, argv ); glutInitWindowSize(640, 480); glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB ); (void)glutCreateWindow("Basic Glut App"); glutReshapeFunc( reshapeFunc ); glutDisplayFunc( displayFunc ); glutKeyboardFunc( keyboardFunc ); glClearColor( 0.0, 0.75, 0.75, 0.0 ); glEnable( GL_DEPTH_TEST ); glutMainLoop(); return 0; // Never called! glutMainLoop() never returns.... }
  9. Opengl app for testing

    Hm, the sucky camera movement at high framerates is because I read in mouse movement with getCursorPos. Therefore when the movement per frame is less than 1 pixel, you get zero angle turn, hence the slowness at high framerates. Can't think of an easy way around this. Anyone know of a function that reads in mouse movement apart from getCursorPos()?
  10. Opengl app for testing

    Comserv, CLAMP_TO_EDGE is used by the programme if it is supported, otherwise it switches to GL_CLAMP, as some older cards have an incorrect implementation of GL_CLAMP which works like CLAMP_TO_EDGE. The correct implementation of CL_CLAMP, so I hear, is to average the edge pixels with the colour of the background, thereby creating a dark border around each of the skybox's faces, which shows up as dark seams on the skybox. I have no solution for cards like DVAD's which have a correct implementation of GL_CLAMP but no CLAMP_TO_EDGE support. Too bad your vsync is on, your fps is limited to your screen refresh rate, which is 60 fps.
  11. Opengl app for testing

    Dvad, 40 fps is probably nearer the truth, I get 50 fps on a GeForce 256, but 80 fps is not impossible. It also depends if you're looking at the empty sky or at the whole geometry. The sky seams are due to older cards not supporting GL_EXT_CLAMP_TO_EDGE in glParameteri(). Dvad can you try the newer version here and tell me if they disappear (this one uses GL_CLAMP instead of GL_REPEAT). Terrax, way to go! That is one hell of a computer you got there. I have a Celeron 2400 with a GeForce FX5600 and I get 236 fps.
  12. newbie:loading textures

    Some tips: 1. read the doc: http://www.lwjgl.org/javadoc/ 2. post on the lwjgl forums 3. use TextureLoader(). Keer :-)
  13. Opengl app for testing

    Thanks for the tip Riptorn, my collision detection apparently still needs some tuning. Here's the texture Sorry, don't remember where I got it from. Btw, ProjectX looks way cool! [Edited by - Keermalec on November 23, 2004 6:12:55 AM]
  14. Opengl app for testing

    Cool, so it actually works on an integrated graphics chipset! Too bad it doesn't support GL_EXT_texture_edge_clamp. Llamaguy, which of the following two images looks more like your sky seams? GL_REPEAT GL_CLAMP And do the seams disappear with this version? Thanks, Keer [Edited by - Keermalec on November 22, 2004 3:52:41 PM]
  15. Opengl app for testing

    Hi, I'm getting really depressed because my new job leaves me no time to work on my project. I would be grateful to know what you think of my little opengl app, is it worth developing further or not? Get it here Look around with mouse and move with arrow keys. Frame rate will print to a text file called mve_log.txt when you press spacebar. Quit with ESC. Many thanks for your opinion, Keer PS: Also please give your OS type, processor speed, type of graphics card, frame rate, and indicate if you have turned vsync off or not (if you don't know what vsync is, then it is on). [Edited by - Keermalec on November 22, 2004 1:23:46 PM]