void SmokeRenderer::render()
{
	switch(mDisplayMode) {
	case POINTS:
		glColor3f(1.0, 1.0, 1.0);
		m_simpleProg->enable();
		drawPoints(0, mNumParticles, false);
		m_simpleProg->disable();
		break;
	case SPRITES:
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
		glColor4f(1.0, 1.0, 1.0, m_spriteAlpha);
		drawPointSprites(m_particleProg, 0, mNumParticles, false);
		break;
	case VOLUMETRIC:
		drawSlices();
		compositeResult();
		break;
	case NUM_MODES:
		break;
	}

    if (m_displayLightBuffer) {
        // display light buffer to screen
        glViewport(0, 0, m_lightBufferSize, m_lightBufferSize);
        glDisable(GL_DEPTH_TEST);
        displayTexture(m_lightTexture[m_srcLightTexture]);
        glViewport(0, 0, mWindowW, mWindowH);
    }

    glutReportErrors();
}
//-------------------------------------------------------------------------------------------
//      描画時の処理です.
//-------------------------------------------------------------------------------------------
void OnDisplay()
{
    // バッファをクリア.
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // テクスチャマッピング有効化
    glEnable(GL_TEXTURE_2D);
    // テクスチャをバインド
    glBindTexture(GL_TEXTURE_2D, g_Texture.GetID());
    // 色の指定
    glColor4f(1.0, 1.0, 1.0, 1.0);

    // 四角形をテクスチャ座標つきで描画
    glBegin(GL_QUADS);
    {
        double size = 0.5;
        glTexCoord2d( 0.0, 1.0 );     glVertex3d( -size, -size, 0.0 );
        glTexCoord2d( 0.0, 0.0 );     glVertex3d( -size,  size, 0.0 );
        glTexCoord2d( 1.0, 0.0 );     glVertex3d(  size,  size, 0.0 );
        glTexCoord2d( 1.0, 1.0 );     glVertex3d(  size, -size, 0.0 );
    }
    glEnd();

    // テクスチャをアンバインド.
    glBindTexture(GL_TEXTURE_2D, 0);
    // テクスチャマッピング無効化
    glDisable(GL_TEXTURE_2D);

    // コマンドを実行して,バッファを交換.
    glutSwapBuffers();

#if defined(DEBUG) || defined(_DEBUG)
    glutReportErrors();
#endif//defined(DEBUG) || defined(_DEBUG)
}
Beispiel #3
0
// initialize OpenGL
void initGL(int *argc, char **argv)
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(width, height);
    glutCreateWindow("CUDA Particles");

    glewInit();

    if (!glewIsSupported("GL_VERSION_2_0 GL_VERSION_1_5 GL_ARB_multitexture GL_ARB_vertex_buffer_object"))
    {
        fprintf(stderr, "Required OpenGL extensions missing.");
        exit(EXIT_FAILURE);
    }

#if defined (_WIN32)

    if (wglewIsSupported("WGL_EXT_swap_control"))
    {
        // disable vertical sync
        wglSwapIntervalEXT(0);
    }

#endif

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.25, 0.25, 0.25, 1.0);

    glutReportErrors();
}
void displayFunc(void)
{
    sdkStartTimer(&timer);
    TColor *d_dst = NULL;
    size_t num_bytes;

    if (frameCounter++ == 0)
    {
        sdkResetTimer(&timer);
    }

    // DEPRECATED: checkCudaErrors(cudaGLMapBufferObject((void**)&d_dst, gl_PBO));
    checkCudaErrors(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
    getLastCudaError("cudaGraphicsMapResources failed");
    checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&d_dst, &num_bytes, cuda_pbo_resource));
    getLastCudaError("cudaGraphicsResourceGetMappedPointer failed");

    checkCudaErrors(CUDA_Bind2TextureArray());

    runImageFilters(d_dst);

    checkCudaErrors(CUDA_UnbindTexture());
    // DEPRECATED: checkCudaErrors(cudaGLUnmapBufferObject(gl_PBO));
    checkCudaErrors(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

    // Common display code path
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageW, imageH, GL_RGBA, GL_UNSIGNED_BYTE, BUFFER_DATA(0));
        glBegin(GL_TRIANGLES);
        glTexCoord2f(0, 0);
        glVertex2f(-1, -1);
        glTexCoord2f(2, 0);
        glVertex2f(+3, -1);
        glTexCoord2f(0, 2);
        glVertex2f(-1, +3);
        glEnd();
        glFinish();
    }

    if (frameCounter == frameN)
    {
        frameCounter = 0;

        if (g_FPS)
        {
            printf("FPS: %3.1f\n", frameN / (sdkGetTimerValue(&timer) * 0.001));
            g_FPS = false;
        }
    }

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);

    computeFPS();
}
////////////////////////////////////////////////////////////////////////////////
//! Initialize OpenGL
////////////////////////////////////////////////////////////////////////////////
CUTBoolean
initGL(int *argc, char **argv)
{
    // Create GL context
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(window_width, window_height);
    glutCreateWindow("CUDA Marching Cubes");

    // initialize necessary OpenGL extensions
    glewInit();
    if (! glewIsSupported("GL_VERSION_2_0 " 
		                  )) {
        fprintf(stderr, "ERROR: Support for necessary OpenGL extensions missing.");
        fflush(stderr);
        return CUTFalse;
    }

    // default initialization
    glClearColor(0.1, 0.2, 0.3, 1.0);
    glEnable(GL_DEPTH_TEST);

    // good old-fashioned fixed function lighting
    float black[] = { 0.0, 0.0, 0.0, 1.0 };
    float white[] = { 1.0, 1.0, 1.0, 1.0 };
    float ambient[] = { 0.1, 0.1, 0.1, 1.0 };
    float diffuse[] = { 0.9, 0.9, 0.9, 1.0 };
    float lightPos[] = { 0.0, 0.0, 1.0, 0.0 };

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);

    glLightfv(GL_LIGHT0, GL_AMBIENT, white);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
    glLightfv(GL_LIGHT0, GL_SPECULAR, white);
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    
    // load shader program
    gl_Shader = compileASMShader(GL_FRAGMENT_PROGRAM_ARB, shader_code);

	if (g_FrameBufferObject) {
		delete g_FrameBufferObject; g_FrameBufferObject = NULL;
	}
	if (g_bFBODisplay) {
		g_FrameBufferObject = new CFrameBufferObject(window_width, window_height, 32, true, GL_TEXTURE_2D);
	}

	glutReportErrors();

    return CUTTrue;
}
// display results using OpenGL
void display()
{
    sdkStartTimer(&timer);

    // execute filter, writing results to pbo
    unsigned int *dResult;

    //DEPRECATED: checkCudaErrors( cudaGLMapBufferObject((void**)&d_result, pbo) );
    checkCudaErrors(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
    size_t num_bytes;
    checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&dResult, &num_bytes, cuda_pbo_resource));
    bilateralFilterRGBA(dResult, width, height, euclidean_delta, filter_radius, iterations, kernel_timer);

    // DEPRECATED: checkCudaErrors(cudaGLUnmapBufferObject(pbo));
    checkCudaErrors(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

    // Common display code path
    {
        glClear(GL_COLOR_BUFFER_BIT);

        // load texture from pbo
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
        glBindTexture(GL_TEXTURE_2D, texid);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

        // fragment program is required to display floating point texture
        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader);
        glEnable(GL_FRAGMENT_PROGRAM_ARB);
        glDisable(GL_DEPTH_TEST);

        glBegin(GL_QUADS);
        {
            glTexCoord2f(0, 0);
            glVertex2f(0, 0);
            glTexCoord2f(1, 0);
            glVertex2f(1, 0);
            glTexCoord2f(1, 1);
            glVertex2f(1, 1);
            glTexCoord2f(0, 1);
            glVertex2f(0, 1);
        }
        glEnd();
        glBindTexture(GL_TEXTURE_TYPE, 0);
        glDisable(GL_FRAGMENT_PROGRAM_ARB);
    }

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);

    computeFPS();
}
Beispiel #7
0
void Display(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPolygonMode(GL_FRONT_AND_BACK, options[OPTION_DISPLAY_WIREFRAME] ? GL_LINE : GL_FILL);
 	
    //Wireframe control
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	/*** Frame Rate Counter ***/

	static int frameCounter = 0;
	static AbsoluteTime  start;
	static WPFloat fps = 0.0;	
	char str[12];
	sprintf(str, "%4.2f fps", fps);
	glRasterPos2f(-1.8, -1.8);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	for (int i = 0; i < 10; i++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
	//Timer stuff
	if (frameCounter == 0) start = UpTime();	
	if (frameCounter == 100) {
		Nanoseconds elapsed = AbsoluteDeltaToNanoseconds(UpTime(), start);
		fps = 100.0 / UnsignedWideToUInt64(elapsed) * 1000000000;		
		frameCounter = 0;
	}
	else frameCounter++;	
	
	/*** ***/			
	
	//Now go to viewing perspeective
	manipulator.applyTransform();

	//Render the surface
	curve->Render(0);
	if (options[OPTION_TANGENT]) {
		WCRay tangent = curve->Tangent(_tangentVal);
		tangent.Render(0);
	}
	if (options[OPTION_INVERSION]) {
		WCVector4 inv = curve->PointInversion(*_ipt);
		glColor4f(0.0, 1.0, 1.0, 1.0);
		glPointSize(4.0);
		_ipt->Render(0);
		glBegin(GL_POINTS);
			glVertex3f(inv.I(), inv.J(), inv.K());
		glEnd();
		pt = _ipt;
	}

	//Swap buffers and start over
	glutSwapBuffers();
	glutReportErrors();
}
Beispiel #8
0
void initGL()
{  
    glewInit();
    if (!glewIsSupported("GL_VERSION_2_0 GL_VERSION_1_5 GL_ARB_multitexture GL_ARB_vertex_buffer_object")) {
        fprintf(stderr, "Required OpenGL extensions missing.");
        exit(-1);
    }

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.25, 0.25, 0.25, 1.0);

    glutReportErrors();
}
Beispiel #9
0
void keyboard_func(unsigned char key, int x, int y) {
  if (key == ESCAPE) { 
    glutDestroyWindow(window); 
    exit(0);                   
  }
  if (key == '+') { 
    if (n_vertices < 50 ) {
      n_vertices++;
      erzeuge_objekt_liste();
      glutPostRedisplay();
      glutReportErrors();
    }
  }
  if (key == '-') { 
    if (n_vertices > 3 ) {
      n_vertices--;
      erzeuge_objekt_liste();
      glutPostRedisplay();
      glutReportErrors();
    }
  }
}
////////////////////////////////////////////////////////////////////////////////
//! Create VBO
////////////////////////////////////////////////////////////////////////////////
void
createVBO(GLuint* vbo, unsigned int size)
{
    // create buffer object
    glGenBuffers(1, vbo);
    glBindBuffer(GL_ARRAY_BUFFER, *vbo);

    // initialize buffer object
    glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glutReportErrors();
}
Beispiel #11
0
void DrawGLScene() {
  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);	

  glLoadIdentity();
  glTranslatef(0.0f, 0.0f,-2.0f);

  glRotatef(rot_x,1.0f,0.0f,0.0f);
  glRotatef(rot_y,0.0f,1.0f,0.0f);
  glCallList(objekt_liste);


  glutSwapBuffers();  /* Wechsele Buffer */
  glutReportErrors();					
}
Beispiel #12
0
void specialkey_func (int key, int x, int y){
  if (key == GLUT_KEY_RIGHT) {
    rot_y += 2.0f;
  }
  if (key == GLUT_KEY_LEFT) {
    rot_y -= 2.0f;
  }
  if (key == GLUT_KEY_UP) {
    rot_x -= 2.0f;
  }
  if (key == GLUT_KEY_DOWN) {
    rot_x += 2.0f;
  }
  glutPostRedisplay();
  glutReportErrors();
}
SmokeRenderer::SmokeRenderer(int maxParticles) :
    mMaxParticles(maxParticles),
    mNumParticles(0),
    mPosVbo(0),
    mVelVbo(0),
    mColorVbo(0),
    mIndexBuffer(0),
    mParticleRadius(0.005f),
	mDisplayMode(VOLUMETRIC),
    mWindowW(800),
    mWindowH(600),
    mFov(40.0f),
    m_downSample(2),
    m_numSlices(32),
	m_numDisplayedSlices(32),
    m_sliceNo(0),
    m_shadowAlpha(0.005),
    m_spriteAlpha(0.1),
    m_doBlur(false),
	m_blurRadius(1.0),
    m_displayLightBuffer(false),
    m_lightPos(5.0, 5.0, -5.0),
	m_lightTarget(0.0, 0.0, 0.0),
	m_lightColor(1.0, 1.0, 0.5),
	m_colorAttenuation(0.1, 0.2, 0.3),
    m_lightBufferSize(256),
    m_srcLightTexture(0),
    m_lightDepthTexture(0),
    m_lightFbo(0),
    m_imageTex(0),
    m_depthTex(0),
    m_imageFbo(0)
{
	// load shader programs
	m_simpleProg = new GLSLProgram(particleVS, simplePS);
    m_particleProg = new GLSLProgram(mblurVS, mblurGS, particlePS);
    m_particleShadowProg = new GLSLProgram(mblurVS, mblurGS, particleShadowPS);

    m_blurProg = new GLSLProgram(passThruVS, blurPS);
    m_displayTexProg = new GLSLProgram(passThruVS, texture2DPS);

    // create buffer for light shadows
    createLightBuffer();

    glutReportErrors();
}
void WCTrimmedNurbsSurface::Render(GLuint defaultProg) {
	//Check to see if the surface is visible
	if (!this->_isVisible) return;
	//Check to see if curve needs to be generated
	if (this->_isDirty) {
		//Generate the surface and trim texture - switch on performance level
		switch(WCTrimmedNurbsSurface::_perfLevel) {
			case TRIMSURFACE_PERFLEVEL_HIGH:	
				this->GenerateSurfaceHigh(); 
				this->GenerateTextureHigh();
				break;
			case TRIMSURFACE_PERFLEVEL_MEDIUM:	
				this->GenerateSurfaceMedium(); 
				this->GenerateTextureMedium();
				break;
			case TRIMSURFACE_PERFLEVEL_LOW:		
				this->GenerateSurfaceLow(); 
				this->GenerateTextureLow();
				break;
		}
		//Generate the index for the curve
		this->GenerateIndex();
		//Mark as clean
		this->_isDirty = false;
	}
/*** Debug ***/	
	//Make sure to use the visualization program
	glUseProgram(this->_visProgram);
	//Set up the texture
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBindTexture(GL_TEXTURE_2D, this->_trimTexture);
	//Draw the geometry
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glEnable(GL_TEXTURE_2D);	
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->_buffers[NURBSSURFACE_INDEX_BUFFER]);
	glBindBuffer(GL_ARRAY_BUFFER, this->_buffers[NURBSSURFACE_VERTEX_BUFFER]);
	glVertexPointer(4, GL_FLOAT, NURBSSURFACE_FLOATS_PER_VERTEX * sizeof(GLfloat), 0);
	glNormalPointer(GL_FLOAT, NURBSSURFACE_FLOATS_PER_VERTEX * sizeof(GLfloat), (GLvoid*)(4*sizeof(GLfloat)));
	glTexCoordPointer(2, GL_FLOAT, NURBSSURFACE_FLOATS_PER_VERTEX * sizeof(GLfloat), (GLvoid*)(7*sizeof(GLfloat)));
	//Draw elements (*2 for each triangle in a lod box, *3 for each vertex in a triangle)
	glDrawElements(GL_TRIANGLES, this->_lod*this->_lod*2*3, GL_UNSIGNED_INT, 0);	
	glDisable(GL_TEXTURE_2D);
	glutReportErrors();
/*** Debug ***/	
}
// initialize OpenGL
void initGL(int *argc, char **argv)
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(winWidth, winHeight);
    glutCreateWindow("CUDA Smoke Particles");

    glewInit();
    if (!glewIsSupported("GL_VERSION_2_0 GL_VERSION_1_5")) {
        fprintf(stderr, "The following required OpenGL extensions missing:\n\tGL_VERSION_2_0\n\tGL_VERSION_1_5\n");
        fprintf(stderr, "  PASSED\n");
        cutilExit(*argc, argv);
        exit(-1);
    }
    if (!glewIsSupported("GL_ARB_multitexture GL_ARB_vertex_buffer_object GL_EXT_geometry_shader4")) {
        fprintf(stderr, "The following required OpenGL extensions missing:\n\tGL_ARB_multitexture\n\tGL_ARB_vertex_buffer_object\n\tGL_EXT_geometry_shader4.\n");
        fprintf(stderr, "  PASSED\n");
        cutilExit(*argc, argv);
        exit(-1);
    }

#if defined (_WIN32)
    if (wglewIsSupported("WGL_EXT_swap_control")) {
        // disable vertical sync
        wglSwapIntervalEXT(0);
    }
#endif

    glEnable(GL_DEPTH_TEST);

    // load floor texture
    char* imagePath = cutFindFilePath("floortile.ppm", argv[0]);
    if (imagePath == 0) {
        fprintf(stderr, "Error finding floor image file\n");
        fprintf(stderr, "  FAILED\n");
        exit(EXIT_FAILURE);
    }
    floorTex = loadTexture(imagePath);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);

    floorProg = new GLSLProgram(floorVS, floorPS);	

    glutReportErrors();
}
void initOpengl()
{
    glewInit();

    if (!glewIsSupported(
        "GL_VERSION_2_0 "
        "GL_ARB_vertex_program "
        "GL_ARB_fragment_program "
        ))
    {
        printf("Unable to load required extension\n");
        exit(-1);
    }

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glEnable(GL_TEXTURE_2D);

    glutReportErrors();
}
Beispiel #17
0
void display()
{
    //cutilCheckError(cutStartTimer(timer));
    sdkStartTimer(&timer);
	if(IsFirstTime){
		IsFirstTime = false;
		psystem->update(); 
		if (renderer) 
			renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
	}
	if (!bPause){
		psystem->update(); 
		if (renderer) 
			renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	for (int c = 0; c < 3; ++c)	{
		camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
		camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
	}
	glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
	glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
	glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);

	glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

	glColor3f(0.0, 0.0, 0.0);
	//glutWireCube(2.0);

	if (renderer) renderer->display();
    //cutilCheckError(cutStopTimer(timer));
    sdkStopTimer(&timer);
	glutSwapBuffers();
	glutReportErrors();
	computeFPS();
}
Beispiel #18
0
// display results using OpenGL (called by GLUT)
void display()
{
    sdkStartTimer(&timer);

    render();

    // display results
    glClear(GL_COLOR_BUFFER_BIT);

    // draw image from PBO
    glDisable(GL_DEPTH_TEST);
    glRasterPos2i(0, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);
    computeFPS();
}
void keyboard_func(unsigned char key, int x, int y) {
  //Zahleneingabe
  if (key=='0' || key=='1' || key=='2' || key=='3' || key=='4'){
    gelenk = key-48;
    
    if(key =='0') {
      printf("Gelenk Nr. 1 (y-Achse) ist aktiv.\n");
    }
    else{
      printf("Gelenk Nr. %i ist aktiv.\n", gelenk);
    }
  }
  
  if(key=='-'){
    if(gelenk==0 && rot0<20.0) rot0 += 1.0f;
    if(gelenk==1 && rot1<45.0) rot1 += 1.0f;
    if(gelenk==2 && rot2<45.0) rot2 += 1.0f;
    if(gelenk==3 && rot3<45.0) rot3 += 1.0f;
    if(gelenk==4 && rot4<45.0) rot4 += 1.0f;
  }
  
  if(key=='+'){
    if(gelenk==0 && rot0>-20.0) rot0 -= 1.0f;
    if(gelenk==1 && rot1>-45.0) rot1 -= 1.0f;
    if(gelenk==2 && rot2>-45.0) rot2 -= 1.0f;
    if(gelenk==3 && rot3>-45.0) rot3 -= 1.0f;
    if(gelenk==4 && rot4>-45.0) rot4 -= 1.0f;
  }
  
  if (key == ESCAPE) { 
    glutDestroyWindow(window); 
    exit(0);                   
  }
  
  glutPostRedisplay();
  glutReportErrors();
}
// display results using OpenGL (called by GLUT)
void display()
{
    sdkStartTimer(&timer);

    // map PBO to get CUDA device pointer
    uchar4 *d_output;
    checkCudaErrors(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
    size_t num_bytes;
    checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes,
                    cuda_pbo_resource));
    render(imageWidth, imageHeight, tx, ty, scale, cx, cy,
           blockSize, gridSize, g_FilterMode, d_output);

    checkCudaErrors(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

    // Common display path
    {
        // display results
        glClear(GL_COLOR_BUFFER_BIT);

#if USE_BUFFER_TEX
        // display using buffer texture
        glBindTexture(GL_TEXTURE_BUFFER_EXT, bufferTex);
        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fprog);
        glEnable(GL_FRAGMENT_PROGRAM_ARB);
        glProgramLocalParameterI4iNV(GL_FRAGMENT_PROGRAM_ARB, 0, width, 0, 0, 0);
#else
        // download image from PBO to OpenGL texture
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
        glBindTexture(GL_TEXTURE_TYPE, displayTex);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexSubImage2D(GL_TEXTURE_TYPE,
                        0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0);
        glEnable(GL_TEXTURE_TYPE);
#endif

        // draw textured quad
        glDisable(GL_DEPTH_TEST);
        glBegin(GL_QUADS);
        glTexCoord2f(0.0f          , (GLfloat)height);
        glVertex2f(0.0f, 0.0f);
        glTexCoord2f((GLfloat)width, (GLfloat)height);
        glVertex2f(1.0f, 0.0f);
        glTexCoord2f((GLfloat)width, 0.0f);
        glVertex2f(1.0f, 1.0f);
        glTexCoord2f(0.0f          , 0.0f);
        glVertex2f(0.0f, 1.0f);
        glEnd();
        glDisable(GL_TEXTURE_TYPE);
        glDisable(GL_FRAGMENT_PROGRAM_ARB);

        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

        if (drawCurves)
        {
            // draw spline curves
            glPushMatrix();
            glScalef(0.25, 0.25, 1.0);

            glTranslatef(0.0, 2.0, 0.0);
            glColor3f(1.0, 0.0, 0.0);
            plotCurve(bspline_w3);

            glTranslatef(1.0, 0.0, 0.0);
            glColor3f(0.0, 1.0, 0.0);
            plotCurve(bspline_w2);

            glTranslatef(1.0, 0.0, 0.0);
            glColor3f(0.0, 0.0, 1.0);
            plotCurve(bspline_w1);

            glTranslatef(1.0, 0.0, 0.0);
            glColor3f(1.0, 0.0, 1.0);
            plotCurve(bspline_w0);

            glPopMatrix();
            glColor3f(1.0, 1.0, 1.0);
        }
    }

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);

    computeFPS();
}
// display results using OpenGL (called by GLUT)
void display()
{
    cutilCheckError(cutStartTimer(timer));  

    // use OpenGL to build view matrix
    GLfloat modelView[16];
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
        glLoadIdentity();
        glRotatef(-viewRotation.x, 1.0, 0.0, 0.0);
        glRotatef(-viewRotation.y, 0.0, 1.0, 0.0);
        glTranslatef(-viewTranslation.x, -viewTranslation.y, -viewTranslation.z);
    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
    glPopMatrix();

    invViewMatrix[0] = modelView[0]; invViewMatrix[1] = modelView[4]; invViewMatrix[2] = modelView[8]; invViewMatrix[3] = modelView[12];
    invViewMatrix[4] = modelView[1]; invViewMatrix[5] = modelView[5]; invViewMatrix[6] = modelView[9]; invViewMatrix[7] = modelView[13];
    invViewMatrix[8] = modelView[2]; invViewMatrix[9] = modelView[6]; invViewMatrix[10] = modelView[10]; invViewMatrix[11] = modelView[14];

    render();

    // display results
    glClear(GL_COLOR_BUFFER_BIT);

    // draw image from PBO
    glDisable(GL_DEPTH_TEST);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#if 0
    // draw using glDrawPixels (slower)
    glRasterPos2i(0, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
#else
    // draw using texture

    // copy from pbo to texture
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

    // draw textured quad
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex2f(0, 0);
    glTexCoord2f(1, 0); glVertex2f(1, 0);
    glTexCoord2f(1, 1); glVertex2f(1, 1);
    glTexCoord2f(0, 1); glVertex2f(0, 1);
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
#endif

    if (g_CheckRender && g_CheckRender->IsQAReadback() && g_Verify) {
        // readback for QA testing
        shrLog("\n> (Frame %d) Readback BackBuffer\n", frameCount);
        g_CheckRender->readback( width, height );
        g_CheckRender->savePPM(sOriginal[g_Index], true, NULL);
        if (!g_CheckRender->PPMvsPPM(sOriginal[g_Index], sReference[g_Index], MAX_EPSILON_ERROR, THRESHOLD)) {
            g_TotalErrors++;
        }
        g_Verify = false;
    }
    glutSwapBuffers();
    glutReportErrors();

    cutilCheckError(cutStopTimer(timer));  

    computeFPS();
}
Beispiel #22
0
// Setup function for GLUT parameters and loop
//*****************************************************************************
void InitGL(int* argc, char** argv)
{  
    // init GLUT 
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowPosition (glutGet(GLUT_SCREEN_WIDTH)/2 - iGraphicsWinWidth/2, 
                            glutGet(GLUT_SCREEN_HEIGHT)/2 - iGraphicsWinHeight/2);
    glutInitWindowSize(iGraphicsWinWidth, iGraphicsWinHeight);
    iGLUTWindowHandle = glutCreateWindow("OpenCL particles");
#if !(defined (__APPLE__) || defined(MACOSX))
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
#endif

    // register GLUT callbacks
    glutDisplayFunc(DisplayGL);
    glutReshapeFunc(ReshapeGL);
    glutMouseFunc(MouseGL);
    glutTimerFunc(REFRESH_DELAY, timerEvent, 0);
    glutMotionFunc(MotionGL);
    glutKeyboardFunc(KeyboardGL);
    glutSpecialFunc(SpecialGL);
    glutIdleFunc(IdleGL);
        
    // init GLEW
    glewInit();
    if (!glewIsSupported("GL_VERSION_2_0 "
                         "GL_VERSION_1_5 "
                         "GL_ARB_multitexture "
                         " GL_ARB_vertex_buffer_object")) 
    {
        shrLog("Required OpenGL extensions missing !!!\n");
        shrQAFinish(*argc, (const char **)argv, QA_FAILED);
        Cleanup(EXIT_FAILURE);
    }

    #ifdef _WIN32
        if (wglewIsSupported("WGL_EXT_swap_control")) 
        {
            // disable vertical sync
            wglSwapIntervalEXT(0);
        }
    #endif
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.25, 0.25, 0.25, 1.0);
    glutReportErrors();
    
    // create GLUT menu    
    iGLUTMenuHandle = glutCreateMenu(MenuGL);
    glutAddMenuEntry("Reset Stacked Block [1]", '1');
    glutAddMenuEntry("Reset Random Paricle Cloud [2]", '2');
    glutAddMenuEntry("Drop particle sphere [3]", '3');
    glutAddMenuEntry("Shoot particle sphere [4]", '4');
    glutAddMenuEntry("Change to 'View' mode [v]", 'v');
    glutAddMenuEntry("Change to 'Move cue-ball' mode [m]", 'm');
    glutAddMenuEntry("Toggle Tour mode [t]", 't');
    glutAddMenuEntry("Toggle point rendering [p]", 'p');
    glutAddMenuEntry("Toggle animation On/Off <spacebar>", ' ');
    glutAddMenuEntry("Toggle between Full Screen and Windowed [f]", 'f');
    glutAddMenuEntry("Step animation <return>", 13);
    glutAddMenuEntry("Toggle sliders [h]", 'h');
    glutAddMenuEntry("Quit <esc>", '\033');
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    // Init view transform
    ResetViewTransform();
}
Beispiel #23
0
void display()
{
    sdkStartTimer(&timer);

    // render
    //MOVE THIS UP
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // update the simulation
    if (!bPause)
    {
        psystem->setIterations(iterations);
        //psystem->setDamping(damping);
        //psystem->setGravity(-gravity);
        //psystem->setCollideSpring(collideSpring);
        //psystem->setCollideDamping(collideDamping);
        //psystem->setCollideShear(collideShear);
        //psystem->setCollideAttraction(collideAttraction);

        psystem->update(timestep);
        num_iter++;

        if (renderer)
        {
            //renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
        	renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles(), psystem->getMaxNumParticles());
        }
    }

    // render
    //MOVE THIS UP
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // view transform
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    for (int c = 0; c < 3; ++c)
    {
        camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
        camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
    }

    glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
    glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
    glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);

    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
/*
    glBegin(GL_LINES);
    //glBegin(GL_POLYGON);
    // cube
    glColor3f(1.0, 1.0, 1.0);
    //glutWireCube(0.2);
    glVertex3f(0.0, 0.0, 0);
    glVertex3f(0.0, 0.0, 0.46);

    glVertex3f(0.0, 0.0, 0.46);
    glVertex3f(0.102, 0.0, 0.46);

    glVertex3f(0.102, 0.0, 0.46);
    glVertex3f(0.102, 0.0, 0.0);

    glVertex3f(0.102, 0.0, 0);
    glVertex3f(0.0, 0.0, 0);
*/
//    for (int i=0;i<m_params.)

    glEnd();

    /*// collider
    glPushMatrix();
    float3 p = psystem->getColliderPos();
    glTranslatef(p.x, p.y, p.z);
    glColor3f(1.0, 0.0, 0.0);
    glutSolidSphere(psystem->getColliderRadius(), 20, 10);
    glPopMatrix();*/

    if (renderer && displayEnabled)
    {
        renderer->display(displayMode);
    }

    if (displaySliders)
    {
        glDisable(GL_DEPTH_TEST);
        glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
        glEnable(GL_BLEND);
        params->Render(0, 0);
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
    }

    sdkStopTimer(&timer);

    glutSwapBuffers();
    glutReportErrors();

    computeFPS();
}
// Primary GLUT callback loop function
//*****************************************************************************
void DisplayGL()
{
    // update the simulation, unless paused
    double dProcessingTime = 0.0;
    if (!bPause)
    {
        // start timer FUNCTIME if it's update time
        if (iFrameCount >= iFrameTrigger)
        {
            shrDeltaT(FUNCTIME); 
        }

        // Run the simlation computations
        nbody->update(activeParams.m_timestep); 
        nbody->getArray(BodySystem::BODYSYSTEM_POSITION);

        // Make graphics work with or without CL/GL interop 
        if (bUsePBO) 
        {
            renderer->setPBO((unsigned int)nbody->getCurrentReadBuffer(), nbody->getNumBodies());
        } 
        else 
        { 
            renderer->setPositions((float*)nbody->getCurrentReadBuffer(), nbody->getNumBodies());
        }

        // get processing time from timer FUNCTIME, if it's update time
        if (iFrameCount >= iFrameTrigger)
        {
            dProcessingTime = shrDeltaT(FUNCTIME); 
        }
    }

    // Redraw main graphics display, if enabled
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
    if (displayEnabled)
    {
        // view transform
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        for (int c = 0; c < 3; ++c)
        {
            camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
            camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
        }
        glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
        glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
        glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);
        renderer->setSpriteSize(activeParams.m_pointSize);
        renderer->display(displayMode);
    }

    // Display user interface if enabled
    if (bShowSliders)
    {
        glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
        glEnable(GL_BLEND);
	    paramlist->Render(0, 0);
        glDisable(GL_BLEND);
    }

    // Flip backbuffer to screen 
    glutSwapBuffers();

    //  If frame count has triggerd, increment the frame counter, and do fps stuff 
    if (iFrameCount++ > iFrameTrigger)
    {
        // If tour mode is enabled & interval has timed out, switch to next tour/demo mode
        dElapsedTime += shrDeltaT(DEMOTIME); 
        if (bTour && (dElapsedTime > demoTime))
        {
            dElapsedTime = 0.0;
            activeDemo = (activeDemo + 1) % numDemos;
            SelectDemo(activeDemo);
        }

        // get the perf and fps stats
        iFramesPerSec = (int)((double)iFrameCount/ shrDeltaT(FPSTIME));
        double dGigaInteractionsPerSecond = 0.0;
        double dGigaFlops = 0.0;
        ComputePerfStats(dGigaInteractionsPerSecond, dGigaFlops, dProcessingTime, 1);

        // If not paused, set the display window title, reset trigger and log info
        char cTitle[256];
        if(!bPause) 
        {
        #ifdef GPU_PROFILING
            #ifdef _WIN32
                sprintf_s(cTitle, 
                        "OpenCL for GPU Nbody Demo (%d bodies): %i fps | %0.4f BIPS | %0.4f GFLOP/s", 
		                numBodies, iFramesPerSec, dGigaInteractionsPerSecond, dGigaFlops);  
            #else 
                sprintf(cTitle, 
                        "OpenCL for GPU Nbody Demo (%d bodies): %i fps | %0.4f BIPS | %0.4f GFLOP/s", 
		                numBodies, iFramesPerSec, dGigaInteractionsPerSecond, dGigaFlops);  
            #endif
        #else
            #ifdef _WIN32
                sprintf_s(cTitle, 
                        "OpenCL for GPU Nbody Demo (%d bodies)", 
		                numBodies, iFramesPerSec, dGigaInteractionsPerSecond);  
            #else 
                sprintf(cTitle, 
                        "OpenCL for GPU Nbody Demo (%d bodies)", 
		                numBodies, iFramesPerSec, dGigaInteractionsPerSecond);  
            #endif
        #endif
            #ifndef __EMSCRIPTEN__
                glutSetWindowTitle(cTitle);
            #else
                printf("%s\n",cTitle);
            #endif
            // Log fps and processing info to console and file 
            shrLog("%s\n", cTitle); 

            // if doing quick test, exit
            if ((bNoPrompt) && (!--iTestSets))
            {
                // Cleanup up and quit
                shrQAFinish2(false, *pArgc, (const char **)pArgv, QA_PASSED);
                Cleanup(EXIT_SUCCESS);
            }

            // reset the frame counter and adjust trigger
            iFrameCount = 0; 
            iFrameTrigger = (iFramesPerSec > 1) ? iFramesPerSec * 2 : 1;
        }
    }

    #ifndef __EMSCRIPTEN__
        glutReportErrors();
    #endif
}
void Init()
{
	glClearColor(1.0,1.0,1.0,1.0);
	glEnable(GL_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHT2);
	glEnable(GL_LIGHTING);

	GLfloat lDiff[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec[] = { 0.0f,0.0f,1.0f,1.0f };
	GLfloat lpos[] = { 0.0,2.5,0.0,1 };

	GLfloat lDiff1[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec1[] = { 1.0f,0.0f,0.0f,1.0f };
	GLfloat lpos1[] = {0.0f,-2.5,1.0,1 };

	GLfloat lDiff2[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec2[] = { 1.0f,0.0f,1.0f,1.0f };
	GLfloat lpos2[] = { 1.5f,0.0,1.0,1 };

	glLightfv(GL_LIGHT0, GL_DIFFUSE, lDiff);
	glLightfv(GL_LIGHT0, GL_SPECULAR, lSpec);
	glLightfv(GL_LIGHT0, GL_POSITION, lpos);

	glLightfv(GL_LIGHT1, GL_DIFFUSE, lDiff1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, lSpec1);
	glLightfv(GL_LIGHT1, GL_POSITION, lpos1);

	glLightfv(GL_LIGHT2, GL_DIFFUSE, lDiff2);
	glLightfv(GL_LIGHT2, GL_SPECULAR, lSpec2);
	glLightfv(GL_LIGHT2, GL_POSITION, lpos2);
	

	tex1 = SOIL_load_OGL_texture(
		"tex1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	tex2 = SOIL_load_OGL_texture(
		"tex2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);


	tex3 = SOIL_load_OGL_texture(
		"tex3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y 
	);

	tex4 = SOIL_load_OGL_texture(
		"pantalla2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	tex5 = SOIL_load_OGL_texture(
		"pantalla1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	tex6 = SOIL_load_OGL_texture(
		"pantalla3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	player.model = glmReadOBJ("ship.obj");
	asteroideModel = glmReadOBJ("Asteroid.obj");
	enemigoModel = glmReadOBJ("rtm_metroid_v2.obj");

	time_begin = glutGet(GLUT_ELAPSED_TIME);

	srand(time(NULL));

	powerups.push_back(Powerup(limites.right +3, random(limites.bottom,limites.top), 0, 70, time_begin + randomTime(tiempo_nivel - 5000)));
	powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 50, 0, time_begin + randomTime(tiempo_nivel - 5000)));

	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000),asteroideModel,0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel,0.4));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.5));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.4));

	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel-5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));

	ammo_length = limites.right * 2;
	hp_length = limites.right * 2;

	time_fin = time_begin + tiempo_nivel;

	player.x = limites.left/2;
	player.y = 0;
	player.z = 1;

	glutReportErrors();
}
// display results using OpenGL (called by GLUT)
void display()
{
    sdkStartTimer(&timer);

    // use OpenGL to build view matrix
    GLfloat modelView[16];
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glRotatef(-viewRotation.x, 1.0, 0.0, 0.0);
    glRotatef(-viewRotation.y, 0.0, 1.0, 0.0);
    glTranslatef(-viewTranslation.x, -viewTranslation.y, -viewTranslation.z);
    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
    glPopMatrix();

    invViewMatrix[0] = modelView[0];
    invViewMatrix[1] = modelView[4];
    invViewMatrix[2] = modelView[8];
    invViewMatrix[3] = modelView[12];
    invViewMatrix[4] = modelView[1];
    invViewMatrix[5] = modelView[5];
    invViewMatrix[6] = modelView[9];
    invViewMatrix[7] = modelView[13];
    invViewMatrix[8] = modelView[2];
    invViewMatrix[9] = modelView[6];
    invViewMatrix[10] = modelView[10];
    invViewMatrix[11] = modelView[14];

    filter();
    render();

    // display results
    glClear(GL_COLOR_BUFFER_BIT);

    // draw image from PBO
    glDisable(GL_DEPTH_TEST);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // draw using texture
    // copy from pbo to texture
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glBindTexture(GL_TEXTURE_2D, volumeTex);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

    // draw textured quad
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0);
    glVertex2f(0, 0);
    glTexCoord2f(1, 0);
    glVertex2f(1, 0);
    glTexCoord2f(1, 1);
    glVertex2f(1, 1);
    glTexCoord2f(0, 1);
    glVertex2f(0, 1);
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);

    computeFPS();
}
Beispiel #27
0
void ParticleRenderer::display(DisplayMode mode /* = PARTICLE_POINTS */)
{
    switch (mode)
    {
        case PARTICLE_POINTS:
            glColor3f(1, 1, 1);
            glPointSize(m_pointSize);
            _drawPoints();
            break;
        case PARTICLE_SPRITES:
        default:
            {
                // setup point sprites
                glEnable(GL_POINT_SPRITE_ARB);
                glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
                glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
                glPointSize(m_spriteSize);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
                glEnable(GL_BLEND);
                glDepthMask(GL_FALSE);

                glUseProgram(m_program);
                GLuint texLoc = glGetUniformLocation(m_program, "splatTexture");
                glUniform1i(texLoc, 0);

                glActiveTextureARB(GL_TEXTURE0_ARB);
                glBindTexture(GL_TEXTURE_2D, m_texture);

                glutReportErrors();

                glColor3f(1, 1, 1);
                
                _drawPoints();

                glUseProgram(0);

                glutReportErrors();

                glDisable(GL_POINT_SPRITE_ARB);
                glDisable(GL_BLEND);
                glDepthMask(GL_TRUE);
            }
            break;
        case PARTICLE_SPRITES_COLOR:
            {
                // setup point sprites
                glEnable(GL_POINT_SPRITE_ARB);
                glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
                glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
                glPointSize(m_spriteSize);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
                glEnable(GL_BLEND);
                glDepthMask(GL_FALSE);

                glUseProgram(m_program);
                GLuint texLoc = glGetUniformLocation(m_program, "splatTexture");
                glUniform1i(texLoc, 0);

                glActiveTextureARB(GL_TEXTURE0_ARB);
                glBindTexture(GL_TEXTURE_2D, m_texture);

                glutReportErrors();

                glColor3f(1, 1, 1);
                
                _drawPoints(true);

                glUseProgram(0);

                glutReportErrors();

                glDisable(GL_POINT_SPRITE_ARB);
                glDisable(GL_BLEND);
                glDepthMask(GL_TRUE);
            }
            break;
    }
}
Beispiel #28
0
static GLUTwindow *
processWindowWorkList(GLUTwindow * window)
{
  int workMask;

  if (window->prevWorkWin) {
    window->prevWorkWin = processWindowWorkList(window->prevWorkWin);
  } else {
    beforeEnd = &window->prevWorkWin;
  }

  /* Capture work mask for work that needs to be done to this
     window, then clear the window's work mask (excepting the
     dummy work bit, see below).  Then, process the captured
     work mask.  This allows callbacks in the processing the
     captured work mask to set the window's work mask for
     subsequent processing. */

  workMask = window->workMask;
  assert((workMask & GLUT_DUMMY_WORK) == 0);

  /* Set the dummy work bit, clearing all other bits, to
     indicate that the window is currently on the window work
     list _and_ that the window's work mask is currently being
     processed.  This convinces __glutPutOnWorkList that this
     window is on the work list still. */
  window->workMask = GLUT_DUMMY_WORK;

  /* Optimization: most of the time, the work to do is a
     redisplay and not these other types of work.  Check for
     the following cases as a group to before checking each one
     individually one by one. This saves about 25 MIPS
     instructions in the common redisplay only case. */
  if (workMask & (GLUT_EVENT_MASK_WORK | GLUT_DEVICE_MASK_WORK |
      GLUT_CONFIGURE_WORK | GLUT_COLORMAP_WORK | GLUT_MAP_WORK)) {
#if !defined(_WIN32)
    /* Be sure to set event mask BEFORE map window is done. */
    if (workMask & GLUT_EVENT_MASK_WORK) {
      long eventMask;

      /* Make sure children are not propogating events this
         window is selecting for.  Be sure to do this before
         enabling events on the children's parent. */
      if (window->children) {
        GLUTwindow *child = window->children;
        unsigned long attribMask = CWDontPropagate;
        XSetWindowAttributes wa;

        wa.do_not_propagate_mask = window->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
        if (window->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK) {
          wa.event_mask = child->eventMask | (window->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK);
          attribMask |= CWEventMask;
        }
        do {
          XChangeWindowAttributes(__glutDisplay, child->win,
            attribMask, &wa);
          child = child->siblings;
        } while (child);
      }
      eventMask = window->eventMask;
      if (window->parent && window->parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
        eventMask |= (window->parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK);
      XSelectInput(__glutDisplay, window->win, eventMask);
      if (window->overlay)
        XSelectInput(__glutDisplay, window->overlay->win,
          window->eventMask & GLUT_OVERLAY_EVENT_FILTER_MASK);
    }
#endif /* !_WIN32 */
    /* Be sure to set device mask BEFORE map window is done. */
    if (workMask & GLUT_DEVICE_MASK_WORK) {
      __glutUpdateInputDeviceMaskFunc(window);
    }
    /* Be sure to configure window BEFORE map window is done. */
    if (workMask & GLUT_CONFIGURE_WORK) {
#if defined(_WIN32)
      RECT changes;
      POINT point;
      UINT flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER
	| SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER;

      GetClientRect(window->win, &changes);
      
      /* If this window is a toplevel window, translate the 0,0 client
         coordinate into a screen coordinate for proper placement. */
      if (!window->parent) {
        point.x = 0;
        point.y = 0;
        ClientToScreen(window->win, &point);
        changes.left = point.x;
        changes.top = point.y;
      }
      if (window->desiredConfMask & (CWX | CWY)) {
        changes.left = window->desiredX;
        changes.top = window->desiredY;
	flags &= ~SWP_NOMOVE;
      }
      if (window->desiredConfMask & (CWWidth | CWHeight)) {
        changes.right = changes.left + window->desiredWidth;
        changes.bottom = changes.top + window->desiredHeight;
	flags &= ~SWP_NOSIZE;
	/* XXX If overlay exists, resize the overlay here, ie.
	   if (window->overlay) ... */
      }
      if (window->desiredConfMask & CWStackMode) {
	flags &= ~SWP_NOZORDER;
	/* XXX Overlay support might require something special here. */
      }

      /* Adjust the window rectangle because Win32 thinks that the x, y,
         width & height are the WHOLE window (including decorations),
         whereas GLUT treats the x, y, width & height as only the CLIENT
         area of the window.  Only do this to top level windows
         that are not in game mode (since game mode windows do
         not have any decorations). */
      if (!window->parent && window != __glutGameModeWindow) {
        AdjustWindowRect(&changes,
          WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
          FALSE);
      }

      /* Do the repositioning, moving, and push/pop. */
      SetWindowPos(window->win,
        window->desiredStack == Above ? HWND_TOP : HWND_NOTOPMOST,
        changes.left, changes.top,
        changes.right - changes.left, changes.bottom - changes.top,
        flags);

      /* Zero out the mask. */
      window->desiredConfMask = 0;

      /* This hack causes the window to go back to the right position
         when it is taken out of fullscreen mode. */
      if (workMask & GLUT_FULL_SCREEN_WORK) {
        window->desiredConfMask |= CWX | CWY;
        window->desiredX = point.x;
        window->desiredY = point.y;
      }
#else /* !_WIN32 */
      XWindowChanges changes;

      changes.x = window->desiredX;
      changes.y = window->desiredY;
      if (window->desiredConfMask & (CWWidth | CWHeight)) {
        changes.width = window->desiredWidth;
        changes.height = window->desiredHeight;
        if (window->overlay)
          XResizeWindow(__glutDisplay, window->overlay->win,
            window->desiredWidth, window->desiredHeight);
        if (__glutMotifHints != None) {
          if (workMask & GLUT_FULL_SCREEN_WORK) {
            MotifWmHints hints;

            hints.flags = MWM_HINTS_DECORATIONS;
            hints.decorations = 0;  /* Absolutely no
                                       decorations. */
            XChangeProperty(__glutDisplay, window->win,
              __glutMotifHints, __glutMotifHints, 32,
              PropModeReplace, (unsigned char *) &hints, 4);
            if (workMask & GLUT_MAP_WORK) {
              /* Handle case where glutFullScreen is called
                 before the first time that the window is
                 mapped. Some window managers will randomly or
                 interactively position the window the first
                 time it is mapped if the window's
                 WM_NORMAL_HINTS property does not request an
                 explicit position. We don't want any such
                 window manager interaction when going
                 fullscreen.  Overwrite the WM_NORMAL_HINTS
                 property installed by glutCreateWindow's
                 XSetWMProperties property with one explicitly
                 requesting a fullscreen window. */
              XSizeHints hints;

              hints.flags = USPosition | USSize;
              hints.x = 0;
              hints.y = 0;
              hints.width = window->desiredWidth;
              hints.height = window->desiredHeight;
              XSetWMNormalHints(__glutDisplay, window->win, &hints);
            }
          } else {
            XDeleteProperty(__glutDisplay, window->win, __glutMotifHints);
          }
        }
      }
      if (window->desiredConfMask & CWStackMode) {
        changes.stack_mode = window->desiredStack;
        /* Do not let glutPushWindow push window beneath the
           underlay. */
        if (window->parent && window->parent->overlay
          && window->desiredStack == Below) {
          changes.stack_mode = Above;
          changes.sibling = window->parent->overlay->win;
          window->desiredConfMask |= CWSibling;
        }
      }
      XConfigureWindow(__glutDisplay, window->win,
        window->desiredConfMask, &changes);
      window->desiredConfMask = 0;
#endif
    }
#if !defined(_WIN32)
    /* Be sure to establish the colormaps BEFORE map window is
       done. */
    if (workMask & GLUT_COLORMAP_WORK) {
      __glutEstablishColormapsProperty(window);
    }
#endif
    if (workMask & GLUT_MAP_WORK) {
      switch (window->desiredMapState) {
      case WithdrawnState:
        if (window->parent) {
          XUnmapWindow(__glutDisplay, window->win);
        } else {
          XWithdrawWindow(__glutDisplay, window->win,
            __glutScreen);
        }
        window->shownState = 0;
        break;
      case NormalState:
        XMapWindow(__glutDisplay, window->win);
        window->shownState = 1;
        break;
#ifdef _WIN32
      case GameModeState:  /* Not an Xlib value. */
        ShowWindow(window->win, SW_SHOW);
        window->shownState = 1;
        break;
#endif
      case IconicState:
        XIconifyWindow(__glutDisplay, window->win, __glutScreen);
        window->shownState = 0;
        break;
      }
    }
  }
  if (workMask & (GLUT_REDISPLAY_WORK | GLUT_OVERLAY_REDISPLAY_WORK | GLUT_REPAIR_WORK | GLUT_OVERLAY_REPAIR_WORK)) {
    if (window->forceReshape) {
      /* Guarantee that before a display callback is generated
         for a window, a reshape callback must be generated. */
      __glutSetWindow(window);
      window->reshape(window->width, window->height);
      window->forceReshape = False;

      /* Setting the redisplay bit on the first reshape is
         necessary to make the "Mesa glXSwapBuffers to repair
         damage" hack operate correctly.  Without indicating a
         redisplay is necessary, there's not an initial back
         buffer render from which to blit from when damage
         happens to the window. */
      workMask |= GLUT_REDISPLAY_WORK;
    }
    /* The code below is more involved than otherwise necessary
       because it is paranoid about the overlay or entire window
       being removed or destroyed in the course of the callbacks.
       Notice how the global __glutWindowDamaged is used to record
       the layers' damage status.  See the code in glutLayerGet for
       how __glutWindowDamaged is used. The  point is to not have to
       update the "damaged" field after  the callback since the
       window (or overlay) may be destroyed (or removed) when the
       callback returns. */

    if (window->overlay && window->overlay->display) {
      int num = window->num;
      Window xid = window->overlay ? window->overlay->win : None;

      /* If an overlay display callback is registered, we
         differentiate between a redisplay needed for the
         overlay and/or normal plane.  If there is no overlay
         display callback registered, we simply use the
         standard display callback. */

      if (workMask & (GLUT_REDISPLAY_WORK | GLUT_REPAIR_WORK)) {
        if (__glutMesaSwapHackSupport) {
          if (window->usedSwapBuffers) {
            if ((workMask & (GLUT_REPAIR_WORK | GLUT_REDISPLAY_WORK)) == GLUT_REPAIR_WORK) {
	      SWAP_BUFFERS_WINDOW(window);
              goto skippedDisplayCallback1;
            }
          }
        }
        /* Render to normal plane. */
#ifdef _WIN32
        window->renderDc = window->hdc;
#endif
        window->renderWin = window->win;
        window->renderCtx = window->ctx;
        __glutWindowDamaged = (workMask & GLUT_REPAIR_WORK);
        __glutSetWindow(window);
        window->usedSwapBuffers = 0;
        window->display();
        __glutWindowDamaged = 0;

      skippedDisplayCallback1:;
      }
      if (workMask & (GLUT_OVERLAY_REDISPLAY_WORK | GLUT_OVERLAY_REPAIR_WORK)) {
        window = __glutWindowList[num];
        if (window && window->overlay &&
          window->overlay->win == xid && window->overlay->display) {

          /* Render to overlay. */
#ifdef _WIN32
          window->renderDc = window->overlay->hdc;
#endif
          window->renderWin = window->overlay->win;
          window->renderCtx = window->overlay->ctx;
          __glutWindowDamaged = (workMask & GLUT_OVERLAY_REPAIR_WORK);
          __glutSetWindow(window);
          window->overlay->display();
          __glutWindowDamaged = 0;
        } else {
          /* Overlay may have since been destroyed or the
             overlay callback may have been disabled during
             normal display callback. */
        }
      }
    } else {
      if (__glutMesaSwapHackSupport) {
        if (!window->overlay && window->usedSwapBuffers) {
          if ((workMask & (GLUT_REPAIR_WORK | GLUT_REDISPLAY_WORK)) == GLUT_REPAIR_WORK) {
	    SWAP_BUFFERS_WINDOW(window);
            goto skippedDisplayCallback2;
          }
        }
      }
      /* Render to normal plane (and possibly overlay). */
      __glutWindowDamaged = (workMask & (GLUT_OVERLAY_REPAIR_WORK | GLUT_REPAIR_WORK));
      __glutSetWindow(window);
      window->usedSwapBuffers = 0;
      window->display();
      __glutWindowDamaged = 0;

    skippedDisplayCallback2:;
    }
  }
  /* Combine workMask with window->workMask to determine what
     finish and debug work there is. */
  workMask |= window->workMask;

  if (workMask & GLUT_FINISH_WORK) {
    /* Finish work makes sure a glFinish gets done to indirect
       rendering contexts.  Indirect contexts tend to have much 
       longer latency because lots of OpenGL extension requests 
       can queue up in the X protocol stream. __glutSetWindow
       is where the finish works gets queued for indirect
       contexts. */
    __glutSetWindow(window);
#if !defined(_WIN32)
    if (!window->isDirect)
#endif
    {
       glFinish();
    }
  }
  if (workMask & GLUT_DEBUG_WORK) {
    __glutSetWindow(window);
    glutReportErrors();
  }
  /* Strip out dummy, finish, and debug work bits. */
  window->workMask &= ~(GLUT_DUMMY_WORK | GLUT_FINISH_WORK | GLUT_DEBUG_WORK);
  if (window->workMask) {
    /* Leave on work list. */
    return window;
  } else {
    /* Remove current window from work list. */
    return window->prevWorkWin;
  }
}
Beispiel #29
0
void display()
{
    static double gflops = 0;
    static double ifps = 0;
    static double interactionsPerSecond = 0;

    // update the simulation
    if (!bPause)
    {
        if (cycleDemo && (sdkGetTimerValue(&demoTimer) > demoTime))
        {
            activeDemo = (activeDemo + 1) % numDemos;
            selectDemo(activeDemo);
        }

        updateSimulation();

        if (!useCpu)
        {
            cudaEventRecord(hostMemSyncEvent, 0);    // insert an event to wait on before rendering
        }
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (displayEnabled)
    {
        // view transform
        {
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            for (int c = 0; c < 3; ++c)
            {
                camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
                camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
            }

            glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
            glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
            glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);
        }

        displayNBodySystem();

        // display user interface
        if (bShowSliders)
        {
            glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
            glEnable(GL_BLEND);
            paramlist->Render(0, 0);
            glDisable(GL_BLEND);
        }

        if (bFullscreen)
        {
            beginWinCoords();
            char msg0[256], msg1[256], msg2[256];

            if (bDispInteractions)
            {
                sprintf(msg1, "%0.2f billion interactions per second", interactionsPerSecond);
            }
            else
            {
                sprintf(msg1, "%0.2f GFLOP/s", gflops);
            }

            sprintf(msg0, "%s", deviceName);
            sprintf(msg2, "%0.2f FPS [%s | %d bodies]",
                    ifps, fp64 ? "double precision" : "single precision", numBodies);

            glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
            glEnable(GL_BLEND);
            glColor3f(0.46f, 0.73f, 0.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 122, msg0, GLUT_BITMAP_TIMES_ROMAN_24);
            glColor3f(1.0f, 1.0f, 1.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 96, msg2, GLUT_BITMAP_TIMES_ROMAN_24);
            glColor3f(1.0f, 1.0f, 1.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 70, msg1, GLUT_BITMAP_TIMES_ROMAN_24);
            glDisable(GL_BLEND);

            endWinCoords();
        }

        glutSwapBuffers();
    }

    fpsCount++;

    // this displays the frame rate updated every second (independent of frame rate)
    if (fpsCount >= fpsLimit)
    {
        char fps[256];

        float milliseconds = 1;

        // stop timer
        if (useCpu)
        {
            milliseconds = sdkGetTimerValue(&timer);
            sdkResetTimer(&timer);
        }
        else
        {
            checkCudaErrors(cudaEventRecord(stopEvent, 0));
            checkCudaErrors(cudaEventSynchronize(stopEvent));
            checkCudaErrors(cudaEventElapsedTime(&milliseconds, startEvent, stopEvent));
        }

        milliseconds /= (float)fpsCount;
        computePerfStats(interactionsPerSecond, gflops, milliseconds, 1);

        ifps = 1.f / (milliseconds / 1000.f);
        sprintf(fps,
                "CUDA N-Body (%d bodies): "
                "%0.1f fps | %0.1f BIPS | %0.1f GFLOP/s | %s",
                numBodies, ifps, interactionsPerSecond, gflops,
                fp64 ? "double precision" : "single precision");

        glutSetWindowTitle(fps);
        fpsCount = 0;
        fpsLimit = (ifps > 1.f) ? (int)ifps : 1;

        if (bPause)
        {
            fpsLimit = 0;
        }

        // restart timer
        if (!useCpu)
        {
            checkCudaErrors(cudaEventRecord(startEvent, 0));
        }
    }

    glutReportErrors();
}
Beispiel #30
0
void display()
{
    // update the simulation
    if (!bPause)
    {
        psystem->setIterations(iterations);
        psystem->setDamping(damping);
        psystem->setGravity(-gravity);
        psystem->setCollideSpring(collideSpring);
        psystem->setCollideDamping(collideDamping);
        psystem->setCollideShear(collideShear);
        psystem->setCollideAttraction(collideAttraction);

        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
    }

    // render
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  

    // view transform
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    for (int c = 0; c < 3; ++c)
    {
        camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
        camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
    }
    glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
    glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
    glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);

    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

    // cube
    glColor3f(1.0, 1.0, 1.0);
    glutWireCube(2.0);

    // collider
    glPushMatrix();
    float4 p = psystem->getColliderPos();
    glTranslatef(p.x, p.y, p.z);
    glColor3f(1.0, 0.0, 0.0);
    glutSolidSphere(psystem->getColliderRadius(), 20, 10);
    glPopMatrix();

    if (displayEnabled)
    {
        renderer->display(displayMode);
    }

    if (displaySliders) {
        glDisable(GL_DEPTH_TEST);
        glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
        glEnable(GL_BLEND);
        params->Render(0, 0);
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
    }

	psystem->debugDraw();

	glDisable(GL_DEPTH_TEST);
	float offsX = 10.f;
	float offsY = 10.f;
	renderer->showProfileInfo(offsX, offsY, 20.f);
	glEnable(GL_DEPTH_TEST);


    glutSwapBuffers();

	{
		 char fps[256];
		 //float ifps = 1.f / (cutGetAverageTimerValue(timer) / 1000.f);
		 switch (psystem->getSimulationMode())
		 {
		 case ParticleSystem::SIMULATION_CUDA:
			 {
				sprintf(fps, "CUDA particles (%d particles)", numParticles);  
				break;
			 }
		case ParticleSystem::SIMULATION_BULLET_CPU:
			 {
				 sprintf(fps, "Bullet btCudaBroadphase (%d btSphereShapes)", numParticles);  
				 break;
			 }
		 default:
			 {
				 sprintf(fps, "Unknown simulation mode");  
			 }
		 }
		 glutSetWindowTitle(fps);
	}

    glutReportErrors();

}