• Content count

  • Joined

  • Last visited

Community Reputation

260 Neutral

About Sybalos

  • Rank

Personal Information

  • Interests
  1. Hi all, I'm having an issue when using QPC/QPF here is my code: [CODE] unsigned frameNumber; unsigned lastFrameTimestamp; unsigned lastFrameDuration; float lastFrameDurationS; void InitTime() { LONGLONG time; qpcFlag = (QueryPerformanceFrequency((LARGE_INTEGER*)&time) > 0); if (qpcFlag) qpcFrequency = 1000.0 / time; } unsigned SystemTime() { if(qpcFlag) { static LONGLONG qpcMillisPerTick; QueryPerformanceCounter((LARGE_INTEGER*)&qpcMillisPerTick); return (unsigned)(qpcMillisPerTick * qpcFrequency); } else { return unsigned(timeGetTime()); } } void Timing::Update() { if(!timingData) return; if(!timingData->isPaused) { timingData->frameNumber++; } // Update the timing information. unsigned thisTime = SystemTime(); timingData->lastFrameDuration = thisTime - timingData->lastFrameTimestamp; timingData->lastFrameTimestamp = thisTime; timingData->lastFrameDurationS = timingData->lastFrameDuration * 0.001f; } [/CODE] When i use this to simulate some physics based animation everything work fine on my laptop and my home pc. But i tried it at my job's PC wich is more powerfull and the animation is jerky. When i use timeGetTime instead everything run smooth on every pc. I confirm that every PC that i tried support the HighRes timer. Here is how i use it: [CODE] actor->m_position += (actor->m_velocity * g_pApp->GetTiming()->lastFrameDurationS); [/CODE] Here is the spec of the problematic PC's processor: [url=""][/url]. Any idea would be apreciate. Thanks.
  2. Hi all! I was wondering what would be the best approach for a simple classic 3D space shooter smooth camera movement. Games like Freelancer, DarkHorizon, SpaceForce have such a smooth camera movement controlled with the mouse. What would be the step to achieve that kind of result ? Any idea will be appreciate! I also want to understand the math behind it. I'm using c++ and directx. Thanks!
  3. Scet, your link show almost wnat im looking. The problem is that ofsteam.write does not compile with an unsigned char* as 1st parameter
  4. Hi all, Im looking for a way to write unsigned char* on disk and read it back. How can i find its size/length. Does anybody have a correct way to do this with ofstream's write methode. My unsigned char* variable point to a bitmap data that i just load with freed(). Please post a solution for both read and write using ofstream from C++ standard. Thx.
  5. thanks... it works. I think i just don't understand when i need a context and when i don't need it ex. glBegin/glEnd etc.
  6. Hi all, I want to code an MFC gui that map texture on poly's. Is there a way to load and generate texture object at run time in an application in OpenGL. It seem that i have to do the glGentextures stuff only at initialization. Does anybody have a solutions on this? thx!
  7. Hi every one, I'm new to picking in opengl. I'm working on a 3D application that need it. So, i look at the gluUnProject function to handle the 2D vs 3D coords (the position of the cursor on the 3D object). I code all the stuff, and it work the way i want except that my object flicker (yes i use double buffering). Also, i think that i have a projection matrix bug because when i click the left mouse button to process hits the projection flicker. I'v try many thing to get there. Here is some code. Thanks for reading (and help if you can). //The render function void CWorld::RenderWorldTest() { glClearColor(0,0, 0, 0); m_tool->Draw3DSGrid(100,m_rgbGridColor ); Draw3DS(GL_RENDER);//draw object PickBunker(m_inputObject);//picking function } //Draw3DS, draw the object. The first function call is the function that update my object position trough picking. void CWorld::Draw3DS(GLenum mode) { if(mode == GL_SELECT) glLoadName(1); UpdateObjetPosition(); // Since we know how many objects our model has, go through each of them. for(int i = 0; i < m_3DModel.numOfObjects; i++) { // Make sure we have valid objects just in case. (size() is in the vector class) if(m_3DModel.pObject.size() <= 0) break; // Get the current object that we are displaying t3DObject *pObject = &m_3DModel.pObject[i]; // Check to see if this object has a texture map, if so bind the texture to it. if(pObject->bHasTexture) { // Turn on texture mapping and turn off color glEnable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); // Bind the texture map to the object by it's materialID if(i == 0) { this->m_texture3DS->SetActiveTextureUnit(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]); } else { this->m_texture3DS->SetActiveTextureUnit(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]); } } else { // Turn off texture mapping and turn on color glDisable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); } // This determines if we are in wireframe or normal mode glBegin(GL_TRIANGLES); // Go through all of the faces (polygons) of the object and draw them for(int j = 0; j < pObject->numOfFaces; j++) // Go through each corner of the triangle and draw it. for(int whichVertex = 0; whichVertex < 3; whichVertex++) { // Get the index for each point of the face int index = pObject->pFaces[j].vertIndex[whichVertex]; // Give OpenGL the normal for this vertex. glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z); // If the object has a texture associated with it, give it a texture coordinate. if(pObject->bHasTexture) { // Make sure there was a UVW map applied to the object or else it won't have tex coords. if(pObject->pTexVerts) { //this->m_texture3DS->glMultiTexCoord2fARB(GL_TEXTURE0_ARB, pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); //this->m_texture3DS->glMultiTexCoord2fARB(GL_TEXTURE1_ARB, pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); if(i==0) { m_texture3DS->SetMultitexCoord(GL_TEXTURE0_ARB, pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); m_texture3DS->SetMultitexCoord(GL_TEXTURE1_ARB, pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); } else { m_texture3DS->SetMultitexCoord(GL_TEXTURE0_ARB, pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); } } } else { // Make sure there is a valid material/color assigned to this object. // You should always at least assign a material color to an object, // but just in case we want to check the size of the material list. // if the size is at least one, and the material ID != -1, // then we have a valid material. if(m_3DModel.pMaterials.size() && pObject->materialID >= 0) // Get and set the color that the object is, since it must not have a texture BYTE *pColor = m_3DModel.pMaterials[pObject->materialID].color; // Assign the current color to this model glColor3ub(pColor[0], pColor[1], pColor[2]); } } // Pass in the current vertex of the object (Corner of current face) glVertex3f( pObject->pVerts[ index ].x + (float) this->m_objetPositionX,pObject->pVerts[ index ].y + (float) this->m_objetPositionY , pObject->pVerts[ index ].z + (float) this->m_objetPositionZ ); } } glEnd(); // End the drawing } glDisable(GL_TEXTURE_2D); glPopMatrix(); //Picking function void CWorld::PickBunker(CInputSystem *inputObject) { GLuint selectBuff[1024]; GLint hits; GLint viewport[4]; GLfloat projectionMatrix[16]; if(!inputObject->ButtonDown(0)) { m_objetSelectionne = 0; return; } glGetIntegerv(GL_VIEWPORT, viewport); glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix); glSelectBuffer(1024, selectBuff); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix( (GLdouble) m_mouseX, (GLdouble) m_mouseY, 2, 2 , viewport); glMultMatrixf(projectionMatrix); glMatrixMode(GL_MODELVIEW); this->Draw3DS(GL_SELECT); //glFlush(); hits = glRenderMode(GL_RENDER); ProcessHits(hits, selectBuff); glMatrixMode(GL_PROJECTION); glPopMatrix(); } //The process hits function void CWorld::ProcessHits(GLint hits, GLuint buffer[]) { this->m_objetSelectionne = buffer[3]; } //And finally the update object position function void CWorld::UpdateObjetPosition() { if((this->m_objetSelectionne == 0) || (!m_inputObject->ButtonDown(0))) return; glPushMatrix(); GLint viewport[4]; GLdouble mvmatrix[16], projmatrix[16]; GLdouble wx, wy, wz; glGetIntegerv (GL_VIEWPORT, viewport); glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix); glGetDoublev (GL_PROJECTION_MATRIX, projmatrix); float depth; glReadPixels((GLdouble) m_mouseX,(GLdouble) m_mouseY,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth); gluUnProject ((GLdouble) m_mouseX, (GLdouble) m_mouseY, depth, mvmatrix, projmatrix, viewport, &wx, &wy, &wz); glPopMatrix() m_objetPositionX = wx; m_objetPositionZ = -wy; }
  8. Retail vs Debug application

    ok thx very much. So now where can i find some info on how to build the retail...?
  9. Retail vs Debug application

    Hi everyone, sorry for my bad english... I want to know what's the difference between debug and retail version of an application (i'm learning c++ with MSVC++, code graphics with opengl). Does the code change ? Why we say that the retail is faster than the debug and how could we optimize it ? thx in advance
  10. 3ds export multi\sub-object

    Hi, I want to import a 3ds model in my engine. Is there a way to import 2 (or more) textures for one model with the multi\sub-material modifier ? i use some code inspired from 3ds file loader from with opengl. thx.
  11. TGA alpha problem

    THX!! Thanks you very much for taking care of beginner
  12. TGA alpha problem

    Hi everyone, Sorry for my bad english but i will do my best Here is the problem I want to load a 32 bit.tga image in my game. I want to place this image as an overlay of the camera (it will serve as the game interface). I need the alpha channel to see 3D model trough the overlay image. So i create my tga object in MSVC++. Everything is fine in 24 bit mode without the alpha, but in 32 bit mode the channel alpha is not effective( my overlay image is still in full opacity). I use the glDrawPixels() function in ortho mode to draw the .tga image. Is there something i didn't enable in openGL because i can't make the tga transparent. I export it from photoshop without the RLE compression. Here is some code inspire of the book OPENGL GAME PROGRAMMING by Kevin Hawkins and Dave Astle, i add it the oop touch. // TGAFile.h: interface for the CTGAFile class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_TGAFILE_H__3854DE6A_7D66_4C65_8B35_8C9684B19FAC__INCLUDED_) #define AFX_TGAFILE_H__3854DE6A_7D66_4C65_8B35_8C9684B19FAC__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CTGAFile { public: CTGAFile(); virtual ~CTGAFile(); //Fonctions int LoadTGAFile(char *filename, CTGAFile *tgaFile); void DrawTGA(long width, long height, unsigned char* bitmapImage); //Attributs //In class instead of a struct unsigned char m_imageTypeCode; short int m_imageWidth; short int m_imageHeight; unsigned char m_bitCount; unsigned char *m_imageData; }; #endif // !defined(AFX_TGAFILE_H__3854DE6A_7D66_4C65_8B35_8C9684B19FAC__INCLUDED_) ///////////////////////////////////////////// //And now the load function ////////////////////////////////// int CTGAFile::LoadTGAFile(char *filename, CTGAFile *tgaFile) { FILE *filePtr; //the file pointer unsigned char ucharBad; //garbage unsigned char data short int sintBad; //garbage short int data long imageSize; //size of TGA image int colorMode; // 4 for RGBA or 3 for RGB long imageIdx; //counter variable unsigned char colorSwap; //swap vriable //Ouvrir le fichier TGA filePtr = fopen(filename, "rb"); if(!filePtr) return 0; //Lire le deux bits inutile fread(&ucharBad, sizeof(unsigned char), 1, filePtr); fread(&ucharBad, sizeof(unsigned char), 1, filePtr); //Read in the image type fread(&tgaFile->m_imageTypeCode, sizeof(unsigned char), 1, filePtr); //for our purpose, the image type should be either a 2 or a 3 if((tgaFile->m_imageTypeCode != 2) && (tgaFile->m_imageTypeCode != 3)) { fclose(filePtr); return 0; } //read 13 bit of data we don't need fread(&sintBad, sizeof(short int),1,filePtr); fread(&sintBad, sizeof(short int),1,filePtr); fread(&ucharBad, sizeof(unsigned char),1,filePtr); fread(&sintBad, sizeof(short int),1,filePtr); fread(&sintBad, sizeof(short int),1,filePtr); // read image Dimension fread(&tgaFile->m_imageWidth,sizeof(short int), 1 , filePtr); fread(&tgaFile->m_imageHeight,sizeof(short int), 1 , filePtr); //read image bit depth fread(&tgaFile->m_bitCount, sizeof(unsigned char),1,filePtr); //read bit dont need fread(&ucharBad, sizeof(unsigned char),1,filePtr); //ColorMode -> 3 = BGR, 4 BGRA colorMode = tgaFile->m_bitCount/8; /*MessageBox(NULL,"Help, Something went wrong.", "Error", MB_ICONERROR | MB_OK);*/ imageSize = tgaFile->m_imageWidth * tgaFile->m_imageHeight * colorMode; //Allocate memory for image data tgaFile->m_imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize); //read in image data fread(tgaFile->m_imageData, sizeof(unsigned char), imageSize, filePtr); //Change BGR to RGB for(imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode) { colorSwap = tgaFile->m_imageData[imageIdx]; tgaFile->m_imageData[imageIdx] = tgaFile->m_imageData[imageIdx + 2]; tgaFile->m_imageData[imageIdx + 2] = colorSwap; } fclose(filePtr); return 1; } //////////////////////////////////// //Finally the drawing function //////////////////////////////////// void CTGAFile::DrawTGA(long width, long height, unsigned char* bitmapImage) { glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glRasterPos2i(0,0); glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, bitmapImage); } //Please help !