Jump to content
  • Advertisement

stu2000

Member
  • Content Count

    75
  • Joined

  • Last visited

Community Reputation

101 Neutral

About stu2000

  • Rank
    Member
  1. Nevermind this post, please delete if you have the power. After two days hacking away at it, I discovered a multitude of problems, including getting the fov from dividing two integers instead of two floats, and not inverting the y axis.<br><br>Stu<br><br>Hello again! I'll start by saying I'm completely new to picking. I have only studied the theory and know what it is 'supposed' to do. Implementing it is a whole different story. So I'm trying to implement 3D picking using OpenGL naming stack feature and have the following code (compiles and runs but doesnt actually work). The current code is below: // This function is called by glut whenever mouse is clicked. void PickObject(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; GLint hits; GLint viewport[4]; if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) { return; } glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer (BUFSIZE, selectBuf); gameState-&gt;RenderInSelectionMode(x, y, viewport, selectBuf); } void GameState::RenderInSelectionMode(int mouseX, int mouseY, GLint * viewport, GLuint selectBuf[]) { GLint hits; glRenderMode(GL_SELECT); gluPickMatrix(mouseX, mouseY, 1,1, viewport); gluPickMatrix ((GLdouble) mouseX, (GLdouble) mouseY, 5.0, 5.0, viewport); glInitNames(); glPushName(1); uni.Render(); // Universe, just a bunch of asteroids (will eventually get to point where each asteroid has own name) glPopName(); glPushName(2); aiManager.Render(); // Renders all the spaceships (will eventually get to point where each spaceship has own name) glPopName(); hits = glRenderMode(GL_RENDER); ProcessHits(hits, selectBuf); } // This code i pretty much pulled from the net, dont care about it much for now, what is important is that it outputs the number of hits and details void GameState::ProcessHits (GLint hits, GLuint buffer[]) { unsigned int i; unsigned int j; GLuint ii; GLuint jj; GLuint names; GLuint *ptr; printf ("hits = %d\n", hits); ptr = (GLuint *) buffer; for (i = 0; i &lt; hits; i++) { /* for each hit */ names = *ptr; printf (" number of names for this hit = %d\n", names); ptr++; printf (" z1 is %g;", (float) *ptr/0x7fffffff); ptr++; printf (" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++; printf (" names are "); for (j = 0; j &lt; names; j++) { /* for each name */ printf ("%d ", *ptr); if (j == 0) /* set row and column */ { ii = *ptr; } else if (j == 1) { jj = *ptr; } ptr++; } printf ("\n"); } } I have included my normal render method in case this helps, it has my normal rendering matrix setup etc. void Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Set the camera position] Vector3F cameraPosition = camera.GetPosition(); Vector3F cameraPOI = camera.GetPointOfInterest(); Vector3F cameraUpVector = camera.GetUpVector(); gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, cameraPOI.x, cameraPOI.y, cameraPOI.z, cameraUpVector.x, cameraUpVector.y, cameraUpVector.z); gameState-&gt;Render(); //glDisable(GL_CULL_FACE); #ifdef FEATURE_HUD hud.Render(); #endif glFlush(); glutSwapBuffers(); //glutPostRedisplay(); /* OpenGL is pipelined, and sometimes waits for a full buffer to execute */ } I get the feeling that I am missing the proper matrix setup in the picking process, such as a loadIdentity here and a gluLookat there. Please advize as to what I need. The program should be able to output one name for if you click on an asteroid, and another name for if you click on a spaceship. Stu
  2. Ok, imagine you had just that blue outline and it was the P from the video. It would be nice if as well as a grid of 1s and 0's representing the blue outline, i had a list of equations built in the form y=mx + c with the starting and end positions on the grid in terms of x or y. This would mean that you culd redraw the outline to be more straight and even use the equations to help recognize the letters/shapes and determine aspects of the object, such as orientation etc. Is that clearer? The hugh transform is along the right lines.
  3. Hello there, This is just a post to ask for help/links to theories to do with automatically generating lines based on an outline. Here is a demo of what im working from / how far I am: As you can see I can create a clear outline of the objects I am trying to track. I can even make the line just one pixel thick or several pixels thick if needed. What I would like now is for another step where the lines of the P are detected and drawn so that they are perfectly straight (not necessarily perfect to the image) and I can use this data later to try to determine which kind of shape I am looking at. This is great for capital letters/numbers in licence plates because they have lots of straight lines except for 6 and 9. Will look into curves later. Thanks again, Stuart p.s. yes I have done google searches and found some interesting articles but they mainly appear to be dealing with general line detection of an entire scene and are far more complex than necessary. I already have a grid 'map' of 1 and 0 showing the outline I want to check for lines.
  4. stu2000

    glOrtho 2d help

    Dont want to sound like a little girl but... Omg thank you, thank you, thank you. I put in your code and got rid of all mipmaps. The thing now runs SUPER fast at 960 x 720 resolution. Its running even faster than it was at 640 x 480 before. I tried not using mipmaps before but must have done something wrong as it would not render but does now. This is so much better than what i thought was possible. Now I can just focus on the tracking part of the project thanks!
  5. stu2000

    glOrtho 2d help

    Thanks for the help - especially that long post from karwost with the comments explaining why each thing was bad and what should be done. I had always thought you needed to use mipmaps if you were going to apply a texture to something that wasnt the same size as the image you were passing in? TBH i only care about speed and not looks as I am doing this for objet recognition/tracking and not for a skype video call type thing. Once i have messed around with the example stuff you have given me I will get back to you . Thanks again you guys are awesome!
  6. stu2000

    glOrtho 2d help

    by the way can someone look at this bit of code in there: // Turn image into texture glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glGenTextures(1,&cameraImageTextureID); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (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); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, frameWidth, frameHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, frame); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth,frameHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,frame); It looks like im creating a texture based on webcam inpu each frame. Is it possible and faster to just edit the texture from last frame rather than go through the whole process again? Would this be better/same or could be improved upon?: static bool generatedTexture = false; if (!generatedTexture) { // Turn image into texture glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glGenTextures(1,&cameraImageTextureID); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (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); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, frameWidth, frameHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, frame); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth,frameHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,frame); generatedTexture = true; } else { gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, frameWidth, frameHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, frame); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth,frameHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,frame); } Stu
  7. stu2000

    glOrtho 2d help

    its amazing how a fresh/different pair of eyes can spot the problem immediately. Thanks! That worked. Stu
  8. Hello there, I am trying to develop a webcam application thingy and would really love this to be 2d rather than 3d, with the webcam feed always taking up the screen. I have spent hours trying to get glOrtho to work for me, but my display of the webcam feed is always offscreen, or just not drawn. I have spent hours on it messing around with disabling lighting/blending etc and experimenting with loadIdentities but for the life of me cannot figure out whats wrong. The key thing is that i have a define ' #define USE_ORTHO ' which is used to switch between 2d and 3d as I dont feel like losing everything in this process and might want to go back at some point to 3d. I have set up a 'setuportho' function which is maybe the cause: void SetupOrtho(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.f, 2.f, 0.f, 2.f, 0.f, 100.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } and my render function is here: void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();//reset matrix glColor3f(0,1,0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); #ifdef USE_ORTHO glBegin(GL_QUADS); glTexCoord2s(1,1); glVertex3f(0.1, 0.1, 0.9); glTexCoord2s(1,0); glVertex3f(0.1, 0.9, 0.9); glTexCoord2s(0,0); glVertex3f(0.9, 0.9, 0.9); glTexCoord2s(0,1); glVertex3f(0.9, 0.1, 0.9); glEnd(); #else glBegin(GL_QUADS); glTexCoord2s(1,1); glVertex3f(-8, -6, -10); glTexCoord2s(1,0); glVertex3f(-8, 6, -10); glTexCoord2s(0,0); glVertex3f(8, 6, -10); glTexCoord2s(0,1); glVertex3f(8, -6, -10); glEnd(); #endif //glDeleteTextures(GL_TEXTURE_2D, &cameraImageTextureID); //glDisable(GL_TEXTURE_2D); glFlush(); SwapBuffers(g_HDC); //bring the back buffer to the foreground } but maybe the problem is burried in the rest of the code with lighting etc. I have uploaded the entire project here: http://www.putfile2.com/f/1049/ntkdtp for those of you who probably find it easier to work in MSVC rather than burying through this text. Hopefully you wont have issues as everything including libs are there. Done in MSVC++ 2008 express 32bit win7. People have had problems in the past figuring out how to download, hence I have got my bro to put in a MASSIVE green download button. That should help. Here is the entire code dump, sorry its kind of long as everyhting is in one file DOH! I was hoping it wouldnt come to this and feel like a smeghead asking for help. #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <vector> #include <windows.h> #include <mmsystem.h> #include "videoInput.h" #include <gl/gl.h> #include <gl/glu.h> #include <tchar.h> #define USE_ORTHO //////Defines //#define BITMAP_ID 0x4D42 //Global variables HDC g_HDC; // global device context bool fullScreen = false; // true = fullscreen;false = windowed bool keyPressed[256]; // holds true for keys that are pressed bool leftMouseButton = false; // is the left mouse button pressed bool rigthMouseButton = false; // is the right mouse button pressed. //unsigned char * pixel_buffer_1; //unsigned char * pixel_buffer_2; #pragma region GLOBLE VARIABLE int size = 921600; int device1 = 0; GLuint cameraImageTextureID; int frameWidth = 640; int frameHeight = 480; // Create a videoInput object videoInput VI; unsigned char * frame = new unsigned char[size]; //-----var about control fps static float lasttime = 0.0f; // store the last time static float lasttime2 = 0.0f; static float currenttime; // store the current time #ifndef USE_ORTHO //light variables structure and names copied (values slightly edited) from 'OpenGL Game Programming' by Kevin Hawkins and Dave Astle, 2001 float ambientLight[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // ambient light float diffuseLight[] = { 1.0f, 1.0f, 1.0f, 1.0f}; // diffuse light float lightPosition[] = { 0.0f, 0.0f, 1000.0f, 1.0f}; // the light position float matAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f}; float matDiff[] = {1.0f, 1.0f, 1.0f, 1.0f}; //end of light variables and copied structure material #endif #pragma endregion void SetupOrtho(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.f, 2.f, 0.f, 2.f, 0.f, 100.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();//reset matrix glColor3f(0,1,0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); #ifdef USE_ORTHO glBegin(GL_QUADS); glTexCoord2s(1,1); glVertex3f(0.1, 0.1, 0.9); glTexCoord2s(1,0); glVertex3f(0.1, 0.9, 0.9); glTexCoord2s(0,0); glVertex3f(0.9, 0.9, 0.9); glTexCoord2s(0,1); glVertex3f(0.9, 0.1, 0.9); glEnd(); #else glBegin(GL_QUADS); glTexCoord2s(1,1); glVertex3f(-8, -6, -10); glTexCoord2s(1,0); glVertex3f(-8, 6, -10); glTexCoord2s(0,0); glVertex3f(8, 6, -10); glTexCoord2s(0,1); glVertex3f(8, -6, -10); glEnd(); #endif //glDeleteTextures(GL_TEXTURE_2D, &cameraImageTextureID); //glDisable(GL_TEXTURE_2D); glFlush(); SwapBuffers(g_HDC); //bring the back buffer to the foreground } void initGL() { glClearColor(0.3f,0.3f,1.0f,1.0f); //clear to blue glFrontFace(GL_CW); //set it so that polygons are drawn clockwise (does have an affect for some reason). glEnable(GL_TEXTURE_2D); #ifndef USE_ORTHO glEnable(GL_LIGHTING); //enable lighting glEnable(GL_DEPTH_TEST); //hidden surface removal glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glShadeModel(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); //do not draw inside of polygons for performance glMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient); glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff); //LIGHTING glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); //set up the ambient element glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); //set up the diffuse element glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); //place the light glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); //-----------------PUTH THIS BACK MAYBE glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //END OF LIGHTING glMatrixMode(GL_PROJECTION); gluPerspective(60,1.0f,0.1f,1000.0f); //set the perspective for 60 degree FOV witha a 1:1 aspect ratio and a close clipping pane of 0.1 and far of 1000 units. glMatrixMode(GL_MODELVIEW); //gluLookAt(0, 100, 100, 0,0,0,0,0,1); //important that glulookat is in the modelview matrix #else glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); //enable lighting glDisable(GL_DEPTH_TEST); //hidden surface removal //glDisable(GL_BLEND); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); SetupOrtho(frameWidth, frameHeight); #endif } void Initialize() { initGL(); // Get first camera frame here //Prints out a list of available devices and returns num of devices found int numDevices = VI.listDevices(); // If you want to capture at a different frame rate (default is 30) specify it here, you are not guaranteed to get this fps though. VI.setIdealFramerate(0, 60); // Setup the first device - there are a number of options: // this could be any deviceID that shows up in listDevices // VI.setupDevice(device1); // Setup the first device with the default settings // VI.setupDevice(device1, VI_COMPOSITE); // or setup device with specific connection type VI.setupDevice(device1, frameWidth, frameHeight); // or setup device with specified video size // VI.setupDevice(device1, 320, 240, VI_COMPOSITE); // or setup device with video size and connection type // VI.setFormat(device1, VI_NTSC_M); // if your card doesn't remember what format it should be // call this with the appropriate format listed above // NOTE: must be called after setupDevice! // Optionally setup a second (or third, fourth ...) device - same options as above // VI.setupDevice(device2); // As requested width and height can not always be accomodated // Make sure to check the size once the device is setup frameWidth = VI.getWidth(device1); frameHeight = VI.getHeight(device1); size = VI.getSize(device1); // pixel_buffer_1 = unsigned char[size]; // pixel_buffer_2 = unsigned char[size]; // To get the data from the device first check if the data is new if (VI.isFrameNew(device1)) { // VI.getPixels(device1, pixel_buffer_1, false, false); //fills pixels as a BGR (for openCV) unsigned char array - no flipping // VI.getPixels(device1, pixel_buffer_2, true, true); //fills pixels as a RGB (for openGL) unsigned char array - flipping! frame = VI.getPixels(device1, true, true); //fills pixels as a BGR (for openGL) unsigned char array - no flipping } // Same applies to device2 etc // To get a settings dialog for the device VI.showSettingsWindow(device1); glGenTextures(1,&cameraImageTextureID); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (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); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, frameWidth,frameHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, frame); // gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, frameWidth, frameHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, frame); // Shut down devices properly // VI.stopDevice(device1); // VI.stopDevice(device2); } void Reshape(int w, int h) { double ww = w; double hh = h; #ifndef USE_ORTHO glViewport(0, 0, w, h); /* Establish viewing area to cover entire window. */ glMatrixMode(GL_PROJECTION); glLoadIdentity (); //replace the current matrix with the Identity Matrix gluPerspective(60, ww/hh,0.1f,1000.0f); glMatrixMode(GL_MODELVIEW); #else SetupOrtho(w, h); #endif } void GameLoop() { // Find out how much time has passed // static double time = timeGetTime(); // double time2 = timeGetTime(); // double timeDiff = (time2 - time) / 1000; // time = time2; // Sort out user input if(keyPressed['W']){} if(keyPressed['S']){} if(keyPressed['A']){} if(keyPressed['D']){} if(keyPressed['B']){} if(keyPressed['R']){} // Capture frame from camera here if (VI.isFrameNew(device1)) { // VI.getPixels(device1, pixel_buffer_1, false, false); // fills pixels as a BGR (for openCV) unsigned char array - no flipping // VI.getPixels(device1, pixel_buffer_2, true, true); // fills pixels as a RGB (for openGL) unsigned char array - flipping! VI.getPixels(device1, frame, false, true); } // End of capture frame from camera /* // Clear the tracker buffer for(unsigned int y=0; y<frameHeight; y++) { for(unsigned int x=0; x<frameWidth; x++) { trackBuffer[x][y] = 0; } } // Process the image for(unsigned int i=0; i<frameHeight; i++) { for(unsigned int j=0; j<frameWidth; j++) { } } // Process the tracker buffer for(unsigned int y=0; y<frameHeight; y++) { for(unsigned int x=0; x<frameWidth; x++) { trackBuffer[x][y] == 0; } } // Render the tracker buffer for(unsigned int y=0; y<frameHeight; y++) { for(unsigned int x=0; x<frameWidth; x++) { if(trackBuffer[x][y] == 1) { } } } */ // End of processing the image // Turn image into texture glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glGenTextures(1,&cameraImageTextureID); glBindTexture(GL_TEXTURE_2D, cameraImageTextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (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); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, frameWidth, frameHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, frame); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth,frameHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,frame); Render(); } void SetupPixelFormat(HDC hDC) { int nPixelFormat; //our pixel format index static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE, 0,0,0,0}; nPixelFormat = ChoosePixelFormat(hDC, &pfd); //chose matching pixel format SetPixelFormat(hDC, nPixelFormat, &pfd); //set the pixel format to DC } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; // rendering context static HDC hDC; // device context int width, height; // window width and height int oldMouseX, oldMouseY; // old mouse coordinates double zDeltaDifference = 0; static short zDelta; switch(message) { case WM_CREATE: hDC = GetDC(hwnd); // get current windows device context g_HDC = hDC; SetupPixelFormat(hDC); // call our pixel format setup function //create rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); return 0; break; case WM_CLOSE: // window is closing // Deselect rendering context and delete it wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); // Send WM_QUIT to message queue PostQuitMessage(0); return 0; break; case WM_SIZE: height = HIWORD(lParam); //retrieve width and height width = LOWORD(lParam); if (height==0) { height=1; } // Reset the viewport to new dimensions glViewport(0,0, width, height); #ifndef USE_ORTHO // Set projection matrix current matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Calculate aspect ratio of window gluPerspective(60.0f, (GLfloat)width/(GLfloat)height, 1.0f, 5000.0f); glMatrixMode(GL_MODELVIEW); //set the modelview matrix glLoadIdentity(); //reset the modelview matrix #else SetupOrtho(width, height); #endif return 0; break; case WM_KEYDOWN: //is a key pressed? keyPressed[wParam] = true; // camera.MoveZ(1); return 0; break; case WM_KEYUP: keyPressed[wParam] = false; return 0; break; case WM_LBUTTONDOWN: leftMouseButton = true; return 0; break; case WM_RBUTTONDOWN: rigthMouseButton = true; return 0; break; case WM_LBUTTONUP: leftMouseButton = false; return 0; break; case WM_RBUTTONUP: rigthMouseButton = false; return 0; break; case WM_MOUSEMOVE: // Save old mouse coordinates // oldMouseX = mouseX; // oldMouseY = mouseY; // Get mouse coordinates from Windows // mouseX = LOWORD(lParam); // mouseY = HIWORD(lParam); // These lines limit the camera's range // if (mouseY < 200) { // mouseY = 200; } // if (mouseY > 450) { // mouseY = 450; } if (leftMouseButton) { // camera.zoom += (mouseY - oldMouseY) * 0.50f; // camera.pitch += (mouseY - oldMouseY) * 0.1f; // camera.angle += (oldMouseX - mouseX) * 0.30f; } /* if (mouseX - oldMouseX != 0) { mouseX - oldMouseX > 0 ? angle += 3.0f : angle -= 3.0f ; } */ return 0; break; case WM_MOUSEWHEEL: // zDelta = GET_WHEEL_DELTA_WPARAM(wParam); // camera.zoom = camera.zoom - (camera.zoom/8 * zDelta/120); //camera movement is proportional, so if your further away zooming is faster. return 0; break; default: break; } return (DefWindowProc(hwnd, message, wParam, lParam)); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX windowClass; // windows class HWND hwnd; // window handle MSG msg; // message bool done; // flag saying when our app is complete DWORD dwExStyle; // window extended style DWORD dwStyle; // window style RECT windowRect; // Screen/display attributes int width = 800; int height = 600; int bits = 32; windowRect.left =(long)0; // set left value to 0 windowRect.right =(long)width; // set right value to requested width windowRect.top =(long)0; // set the top value to 0 windowRect.bottom =(long)height; // set bottom value to requested height // Fill out the windows class structure windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); windowClass.hbrBackground = NULL; windowClass.lpszMenuName = NULL; windowClass.lpszClassName = L"MyClass"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Register the windows class if (!RegisterClassEx(&windowClass)) return 0; if (fullScreen) //full screen { DEVMODE dmScreenSettings; //device mode memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; //screen width dmScreenSettings.dmPelsHeight = height; //screen height dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PANNINGHEIGHT; if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { // Setting display mode failed, switch to windowed MessageBox(NULL, L"Display mode failed", NULL, MB_OK); fullScreen=FALSE; } } if (fullScreen) //are we still in full screen mode { dwExStyle=WS_EX_APPWINDOW; //window extended style dwStyle=WS_POPUP; //window style ShowCursor(FALSE); //hide mouse pointer } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; //window exteded style dwStyle=WS_OVERLAPPEDWINDOW; //window style } AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); // Class registered so now create our window hwnd = CreateWindowEx(NULL, L"MyClass", L"Stuart Page's Physics Game", dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0,0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, NULL, NULL, hInstance, NULL); // Check if window creation failed (hwnd would equal NULL) if(!hwnd) return 0; ShowWindow(hwnd, SW_SHOW); //display the window UpdateWindow(hwnd); //update the window done = false; //initialize the loop condition variable // Main message loop Initialize(); while (!done) { if(PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE)!=0) //there is a new message in the que { if(msg.message == WM_QUIT) //do we recieve a WM_QUIT message? { done = true; } else { //GAME LOOP HERE GameLoop(); TranslateMessage(&msg); DispatchMessage(&msg); } } else //there are no new messages, so dont handle any { GameLoop(); } } if (fullScreen) { ChangeDisplaySettings(NULL, 0); //if so switch back to the desktop ShowCursor(TRUE); } return msg.wParam; }
  9. Muchos kudos goes out to Panayiotis Tsamouris for supplying me with this via email. http://code.google.com/p/mestrado-biocomp/source/browse/trunk/prefix-transposition-all/factoradic.c?spec=svn19&r=19 This is exactly what I needed and now can move on. Stu
  10. stu2000

    Relative path files opening

    I highly doubt its specific to PS3, Im pretty certain its just specific to MSVC++ 2008 and could be done on a normal solution.
  11. stu2000

    Relative path files opening

    In the entire solution I have only two references to the file like so: #include "NetCollisionManager.h" one of which is in the corresponding .cpp file. does that help?
  12. Hello there, This has been bugging me for ages now. Whenever I have compiled with errors I will look at my error list in MSVC ++ 2008, double click on the error to go to it and then try to fix it. Unfortunately, this usually opens up a tab for the file with the relative path as shown in the print screen: Whenver performing clicking a search result in the find window, or just opening a file, it will correctly open the file with a tab for the full path as shown here: Unfortunately this means with both tabs open, if you make changes to both and then hit save all, you have a problem. You will get a message asking whether you would like to reload the file because it has been modified etc. If you hit yes, you are likely to lose some of the changes you made, if no, you are going to have to spend ages figuring out what changes you made to each file. Is there any way to make sure that the error window ONLY opens the full path tab or whatever? I dont know how this problem arrived in the first place. Stu
  13. Unless the card on which it's running contains a flux capacitor or graviton generator, then the laws of physics still hold. Even on GPU, memory access patterns are crucial. Morton order, Sloan or Cuthill-McKee ordering, tricks like that all matter. [/quote] I wasnt referring to anything amazing in the field of physics, just referring to this section that I had read: One key difference is in how the two architectures address the issue of accessing off-chip memory, a very expensive operation with hundreds clock cycles of latency. CPUs devote a lot of transitors to on-chip caches in order to reduce as much as possible the overall latency caused by off-chip memory accesses. For applications with no or very little parallelism, this latency reduction is the best strategy. For applications with a high number of parallel computations, another strategy is to ensure that the processor is always busy with some computations while other computations are waiting on memory accesses or at synchronization points. In other words, latency is “hidden” rather than reduced. This latency NVIDIA OpenCL Programming for the CUDA Architecture 3 hiding strategy adopted by GPUs is schematized in Figure 1. Latency hiding requires the ability to quickly switch from one computation to another. A GPU multiprocessor (i.e. a compute unit in OpenCL terminology) is therefore designed to support hundreds of active threads at once and unlike CPUs, the cost of switching from one thread to another is insignificant src: http://www.nvidia.co...ingOverview.pdf Yes I had been building upon this point ( that gpu's work best in an independent state) for this algorithm, stating that I had wanted to create permutations from a continually increasing index. This way each thread is given its own integer index and creates its own permutation from which to calculate the route length (TSP) This will be many more than one instruction. However, it seems that it is very much more calculation intensive to create a permutation from an index, rather than carry on in a recursive method from the previous permutation and thats where this whole thing about shared communication/memory seems to have popped out from. I would still like to see if running lots of threads on a GPU, completely independent, but more calculation intensive (generate permutations from index) as a whole is faster or slower than running a single thread recursive algorithm on a CPU. Stu
  14. Of course that's true. But think about this logically. Your GPU does not have 65536*512=33554432 processing elements in it. It cannot do 33554432 things at the same time. Why would it? Your monitor doesn't even have that many pixels. A CUDA thread is not intended to process exactly one thing and then die. The overhead involved in the creation of a thread is small, but it is greater than the overhead of processing exactly one thing. Bottom line: You will have thousands of threads. You will not have millions. Each thread should do thousands or millions of things, not one thing. EDIT: Incidentally, one of the most important aspects of CUDA is that threads within a block do NOT have to be fully independent. That's going to become important when you want to figure out which path produces the lowest cost: Without intra-block communication through shared memory, you'll need to go to global (GPU) memory for each step in the reduction, which will be SLOOOOOOOOOOOOOOW. [/quote] Ah k thx for that. I had just figured that the algorithm to generate the permutation from a single index would be several steps, not just one instruction, and even about 300 of those running at the same time would be faster than a single cpu thread that has an easier time going from one permutation to another. I read somewhere that cuda works well because it hides memory access latencies by running other threads during this time so even though memmory is slow, this is 'hidden' though this is probably referring to accessing the gpu local/texture memory rather than the global memory, I don't know. However you have a very good point about inter block communication, after all there's no point making it slower when it can be faster even if it is simpler to implement/imagine with each thread being completely independent.
  15. No, the two should be considered to be the same. 2) im actualy usingthis for CUDA and will have a single thread for calculating each and every permutaiton. The index will be generated from the threadIdx.x + blockIdx.x etc.[/quote]That's really not how you're supposed to use CUDA threads. If I recall, even the latest modern hardware limits you to about 1500 threads total in a kernel. CUDA uses for-loops just like everyone else. [/quote] From reading Cuda by example you are limited to 512 threads per block and are alowed to run up to 65535 blocks. From everything I read, CUDA works best the more parallel blocks/threads you can have. Cuda applications only show huge performance increase over CPUs when you launch hundreds/thousands of parallel actions. I should probably have not used the word thread earlier but it seemed appropriate than explaining launching many parallel kernels/blocks with many threads. Im still not 100% on it as you can see. Stu
  • 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!