コード例 #1
0
ファイル: Gines.cpp プロジェクト: ThePr3/Gines
	void endMainLoop()
	{
		console.render();
		drawFPS();
		SDL_GL_SwapWindow(mWindow);
		endFPS();
	}
コード例 #2
0
void display()
{

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glLoadIdentity();
  gluLookAt(0, 0, 20 + zoomValue, 0, 0, 0, 0, 1, 0);

  // multiply current matrix with arcball matrix
  glMultMatrixf( arcball.get() );

  GLUquadric *sphere = gluNewQuadric(); 
  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
   calculateFPS();
  _time_inter = diff_seconds();
  animateObject(); 
  //draw_sun();
    if (mode==0) {
      moebius();
      glutPostRedisplay();
    }
    else {
      glCallList(MOEBIUS);
      glutPostRedisplay();
    }
 
  drawFPS();
  glutPostRedisplay(); 
  glutSwapBuffers();
}
コード例 #3
0
ファイル: main.cpp プロジェクト: ahnm/cis565-project
////////////////////////////////////////////////////////////////////////////////
//! Display callback
////////////////////////////////////////////////////////////////////////////////
void display(void)
{
	runSPG4(vbo_pos, deltatime);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set view matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, translate_z);
    glRotatef(rotate_x, 1.0, 0.0, 0.0);
    glRotatef(rotate_y, 0.0, 1.0, 0.0);
	
    glColor3f(0.0, 0.0, 1.0);
	glutWireSphere(1.0, 90.0, 90.0);

    // render from the vbo with newPos
    glBindBuffer(GL_ARRAY_BUFFER, vbo_pos[0]);
    glVertexPointer(4, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glColor3f(0.0, 1.0, 0.0);
    glDrawArrays(GL_POINTS, 0, numberSatellites);
    glDisableClientState(GL_VERTEX_ARRAY);
	
    drawFPS();
    glutSwapBuffers();

}
コード例 #4
0
ファイル: showfps.c プロジェクト: ghub/NVprSDK
double handleFPS(void)
{
  double lastFpsRate = just_handleFPS();
  if (reportFPS) {
    drawFPS(lastFpsRate);
  }
  return lastFpsRate;
}
コード例 #5
0
ファイル: FPS.cpp プロジェクト: AM1244/Blog
//-------------------------------------------------------------------------
//  This function is passed to glutDisplayFunc in order to display 
//	OpenGL contents on the window.
//-------------------------------------------------------------------------
void display (void)
{
	glClear (GL_COLOR_BUFFER_BIT);

    drawObject();
    drawFPS();
	
	glutSwapBuffers ();
}
コード例 #6
0
void GlutWindow::display()
{
	deferredShader.draw(scene,camera);
	if(stateManager.getRenderTransperency())
	{
		transperencyRenderer.draw(scene,camera);
	}
	drawFPS();
	glutSwapBuffers();
}
コード例 #7
0
void ElevatorSimRenderWindow::draw() {
   SimulationState& simState = SimulationState::acquire();

   if(!valid()) {
      /* init, this code only gets executed the first time draw() is called */

      simState.lockBASM(); /* CRITICAL SECTION START */
      simState.initRenderObjs();
      simState.unlockBASM(); /* CRITICAL SECTION STOP */

      glInit();
      setViewport();
   }

   /* draw */
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   /* TODO: make these constants somewhere */
   gluPerspective(45.0f, (GLfloat)w()/(GLfloat)h(), 0.1f, 500.0f);

   simState.lockBASM(); /* CRITICAL SECTION START */
   simState.getCameraManager().render();

   glMatrixMode(GL_MODELVIEW);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   simState.getBuilding().render();

   int curFPS = simState.getTimeManager().getFPS();
   int curTotalFrames = simState.getTimeManager().getTotalFrames();

   SimulationState::StateKind currentSimState = simState.getStateUnsafe();
   simState.unlockBASM(); /* CRITICAL SECTION STOP */


   if(currentSimState == SimulationState::SIMULATION_RUNNING &&
            m_bRenderFPS) {
      drawFPS(curFPS, curTotalFrames);
   }

   /* glTranslatef(0.f, 3.f, 3.f);
    * glCallList(cRenderObjs::OBJ_HUMAN); */

   GLenum err = glGetError();
   if ( err != GL_NO_ERROR ) {
      std::stringstream dbgSS;
      dbgSS << "GLGETERROR= " << (int) err << std::endl;
      LOG_ERROR( Logger::SUB_RENDER, sstreamToBuffer(dbgSS) );
   }
}
コード例 #8
0
ファイル: glwidget.cpp プロジェクト: lgarest/42
/*
========================
paintGL
========================
*/
void CGLWidget::paintGL( void )
{
	if( !m_initSucceeded )
		return;

	glViewport( 0,0, m_viewportSize.width(), m_viewportSize.height() );

	emit render();

	drawFPS();
}
コード例 #9
0
C_RESULT overlay_stage_transform(vlib_stage_decoding_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
{
	vp_os_mutex_lock( &out->lock );

	if(out->status == VP_API_STATUS_INIT)
	{
		out->status = VP_API_STATUS_PROCESSING;
		out->numBuffers   = 1;
		out->indexBuffer  = 0;
		out->lineSize     = NULL;
	}

	if( in->status == VP_API_STATUS_ENDED )
	{
		out->status = in->status;
	}

	if(in->status == VP_API_STATUS_STILL_RUNNING)
	{
		out->status = VP_API_STATUS_PROCESSING;
	}

	if(out->status == VP_API_STATUS_PROCESSING )
	{
		vp_os_mutex_lock( &overlay_video_config.mutex );

		pixbuf_data = (uint8_t*)in->buffers[0];

		if (overlay_video_config.showFPS) drawFPS(pixbuf_data);

		drawBattery(pixbuf_data);
		drawFlyMode(pixbuf_data);
		drawRecording(pixbuf_data);

//		if (overlay_video_config.showInternalTrackingPoints) drawInternaltrackingPoints(pixbuf_data);
		if (overlay_video_config.showExternalTrackingPoints) drawExternaltrackingPoints(pixbuf_data);


		out->numBuffers = in->numBuffers;
		out->indexBuffer = in->indexBuffer;
		out->size     = in->size;
		out->status   = in->status;
		out->buffers  = in->buffers;

		vp_os_mutex_unlock( &overlay_video_config.mutex );
	}

	vp_os_mutex_unlock( &out->lock );

	return C_OK;
}
コード例 #10
0
ファイル: showfps.c プロジェクト: Rayzan/home-folder
void handleFPS(void)
{
  static int frameCount = 0;     /* Number of frames for timing */
  static double lastFpsRate = 0;
#ifdef _WIN32
  /* Use Win32 performance counter for high-accuracy timing. */
  static __int64 freq = 0;
  static __int64 lastCount = 0;  /* Timer count for last fps update */
  __int64 newCount;

  if (!freq) {
    QueryPerformanceFrequency((LARGE_INTEGER*) &freq);
  }

  /* Update the frames per second count if we have gone past at least
     a second since the last update. */

  QueryPerformanceCounter((LARGE_INTEGER*) &newCount);
  frameCount++;
  if (((newCount - lastCount) > freq) && reportFPS) {
    double fpsRate;

    fpsRate = (double) (freq * (__int64) frameCount)  / (double) (newCount - lastCount);
    lastCount = newCount;
    frameCount = 0;
    lastFpsRate = fpsRate;
  }
#else
  /* Use BSD 4.2 gettimeofday system call for high-accuracy timing. */
  static struct timeval last_tp = { 0, 0 };
  struct timeval new_tp;
  double secs;
  
  gettimeofday(&new_tp, NULL);
  secs = (new_tp.tv_sec - last_tp.tv_sec) + (new_tp.tv_usec - last_tp.tv_usec)/1000000.0;
  if (secs >= 1.0) {
    lastFpsRate = frameCount / secs;
    last_tp = new_tp;
    frameCount = 0;
  }
  frameCount++;
#endif
  if (reportFPS) {
    drawFPS(lastFpsRate);
  }
}
コード例 #11
0
ファイル: main.cpp プロジェクト: RandomWalkEagle/surfDetect
int mainVideo(void)
{
  // Initialise capture device
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  if(!capture) error("No Capture");

  // Initialise video writer
  //cv::VideoWriter vw("c:\\out.avi", CV_FOURCC('D','I','V','X'),10,cvSize(320,240),1);
  //vw << img;

  // Create a window 
  cvNamedWindow("OpenSURF", CV_WINDOW_AUTOSIZE );

  // Declare Ipoints and other stuff
  IpVec ipts;
  IplImage *img=NULL;

  // Main capture loop
  while( 1 ) 
  {
    // Grab frame from the capture source
    img = cvQueryFrame(capture);

    // Extract surf points
    surfDetDes(img, ipts, false, 4, 4, 2, 0.004f);    

    // Draw the detected points
    drawIpoints(img, ipts);

    // Draw the FPS figure
    drawFPS(img);

    // Display the result
    cvShowImage("OpenSURF", img);

    // If ESC key pressed exit loop
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  cvReleaseCapture( &capture );
  cvDestroyWindow( "OpenSURF" );
  return 0;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: flair2005/TDSmoke
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    
    g_simulation_ensemble->display();
    
#ifdef PNGOUT
    drawDescription();
#else
    drawFPS();
#endif
    
    glutSwapBuffers();
    
    assert( renderingutils::checkGLErrors() );
}
コード例 #13
0
//this is where the actual drawing happens
void display() {

	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

	glLoadIdentity();

	camApply(g_Camera);

	drawFPS();

	processList();

	glFlush();

	if (!g_bPicking) {
		glutSwapBuffers();
	}
	else {
		finishPicking();
	}
}
コード例 #14
0
ファイル: main.cpp プロジェクト: rspencer01/Project-Magrathea
void display(void)
{
	keyOperations();
	glClearColor (skyColor[0],skyColor[1],skyColor[2],skyColor[3]);
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	
	glLoadIdentity();
	
	resetStats();
	
	glMatrixMode(GL_MODELVIEW);
	
	camera->Render();
	RenderSky(camera->GetX(),camera->GetZ());
	Island->Render(camera->GetX(),camera->GetZ());
	
	drawFPS();
	writeString(10, 80,"Camera Position: %.2f %.2f %.2f",camera->GetX(),camera->GetY(),camera->GetZ());
	displayHUD();
	glutSwapBuffers();
}
コード例 #15
0
   void ElevatorSimRenderWindow::draw() {
      if(!valid()) {
         /* initialize, this code only gets executed the first time draw() is called */

         m_renderObjs.init();
         glInit();
         setViewport();
      }

      /* draw */
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      /* TODO: make these constants somewhere */
      gluPerspective(45.0f, (GLfloat)w()/(GLfloat)h(), 0.1f, 500.0f);

      m_CameraManager.Render();

      glMatrixMode(GL_MODELVIEW);

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);

      /* Draw building object */
      glLoadIdentity();
      glTranslatef(0.0f, -2.0f, 0.0f);
      glCallList(OBJ_BUILDING);

      if(m_bRenderFPS)  drawFPS();

      GLenum err = glGetError();
      if ( err != GL_NO_ERROR ) {
         fprintf(stderr, "GLGETERROR=%d\n", (int)err);
      }
   }
コード例 #16
0
ファイル: dxdraw.cpp プロジェクト: nekocode/FScript0.15
//==================================
//  函数:textRender()
//  目的:文本渲染
//
void textRender()
{
	/*/显示xy坐标
	int x,y;
	wchar_t xt[15],yt[15];
	GetMousePos(x,y);

	swprintf(xt,15,L"X: %d",x);
	drawtext(xt,0,50);

	swprintf(yt,15,L"Y: %d",y);
	drawtext(yt,0,70);//*/


	if(fpsOn)
		drawFPS();

	if(echoOn&&(stop!=2&&stop!=-2&&stop!=3&&stop!=-3&&stop!=4))
		echo(echotext);

	if(rolenamePicOn&&(stop!=2&&stop!=-2&&stop!=3&&stop!=-3&&stop!=4))
		drawrolename(rolename);
}
コード例 #17
0
ファイル: main.cpp プロジェクト: namenu/SpecialTraning
static void drawScene()
{
    long draw_start = glutGet(GLUT_ELAPSED_TIME);
    
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    
	// Draw Background
    
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, BackgroundTextureID);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    
	glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f((float)Width, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f((float)Width, (float)Height, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, (float)Height, 0.0f);
	glEnd();
    
    glDisable(GL_TEXTURE_2D);
    
    engine.Draw();
    
    drawFPS();
    
	glutSwapBuffers();
    
    timer_draw = glutGet(GLUT_ELAPSED_TIME) - draw_start;
}
コード例 #18
0
ファイル: gltron.c プロジェクト: BackupTheBerlios/gltron-svn
void drawGame() {
  GLint i;
  gDisplay *d;
  Player *p;

  polycount = 0;
  glClearColor(.0, .0, .0, .0);
  glDepthMask(GL_TRUE);
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glDepthMask(GL_FALSE);

  for(i = 0; i < vp_max[ game->settings->display_type]; i++) {
    p = &(game->player[ game->settings->content[i] ]);
    if(p->display->onScreen == 1) {
      d = p->display;
      glViewport(d->vp_x, d->vp_y, d->vp_w, d->vp_h);
      drawCam(p, d);
      drawScore(p, d);
      if(game->settings->show_ai_status)
	if(p->ai->active == 1)
	  drawAI(d);
    }
  }

  if(game->settings->show_2d > 0)
    drawDebugTex(game->screen);
  if(game->settings->show_fps)
    drawFPS(game->screen);

  /*
  if(game->settings->show_help == 1)
    drawHelp(game->screen);
  */

  /* printf("%d polys\n", polycount); */
}
コード例 #19
0
ファイル: main.cpp プロジェクト: RandomWalkEagle/surfDetect
int mainMatch(void)
{
  // Initialise capture device
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  if(!capture) error("No Capture");

  // Declare Ipoints and other stuff
  IpPairVec matches;
  IpVec ipts, ref_ipts;
  
  // This is the reference object we wish to find in video frame
  // Replace the line below with IplImage *img = cvLoadImage("imgs/object.jpg"); 
  // where object.jpg is the planar object to be located in the video
  IplImage *img = cvLoadImage("../imgs/object.jpg"); 
  if (img == NULL) error("Need to load reference image in order to run matching procedure");
  CvPoint src_corners[4] = {{0,0}, {img->width,0}, {img->width, img->height}, {0, img->height}};
  CvPoint dst_corners[4];

  // Extract reference object Ipoints
  surfDetDes(img, ref_ipts, false, 3, 4, 3, 0.004f);
  drawIpoints(img, ref_ipts);
  showImage(img);

  // Create a window 
  cvNamedWindow("OpenSURF", CV_WINDOW_AUTOSIZE );

  // Main capture loop
  while( true ) 
  {
    // Grab frame from the capture source
    img = cvQueryFrame(capture);
     
    // Detect and describe interest points in the frame
    surfDetDes(img, ipts, false, 3, 4, 3, 0.004f);

    // Fill match vector
    getMatches(ipts,ref_ipts,matches);
    
    // This call finds where the object corners should be in the frame
    if (translateCorners(matches, src_corners, dst_corners))
    {
      // Draw box around object
      for(int i = 0; i < 4; i++ )
      {
        CvPoint r1 = dst_corners[i%4];
        CvPoint r2 = dst_corners[(i+1)%4];
        cvLine( img, cvPoint(r1.x, r1.y),
          cvPoint(r2.x, r2.y), cvScalar(255,255,255), 3 );
      }

      for (unsigned int i = 0; i < matches.size(); ++i)
        drawIpoint(img, matches[i].first);
    }

    // Draw the FPS figure
    drawFPS(img);

    // Display the result
    cvShowImage("OpenSURF", img);

    // If ESC key pressed exit loop
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  // Release the capture device
  cvReleaseCapture( &capture );
  cvDestroyWindow( "OpenSURF" );
  return 0;
}
コード例 #20
0
   void ElevatorSimRenderWindow::draw() {
      if(!valid()) {
         /* initialize, this code only gets executed the first time draw() is called */

         m_renderObjs.Init();
         glInit();
         setViewport();

         srand((unsigned)time(NULL));
         for(int i=0; i<g_nNumberOfElev; i++)   {
            elevPos[i] = (float)(rand() % g_nNumberOfFloor);
            elevGoingDown[i] = (rand() % 2 == 1 ? true : false);
         }
      }

      /* draw */
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      gluPerspective(45.0f, (GLfloat)w()/(GLfloat)h(), 0.1f, 500.0f);

      m_CameraManager.Render();

      glMatrixMode(GL_MODELVIEW);
      
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);

      /* Draw building object */
      glLoadIdentity();
      glTranslatef(0.0f, -2.0f, 0.0f);
      glCallList(OBJ_BUILDING);

      /* Draw Elevators; */
      float buildingLeft = -g_nNumberOfElev * ELEV_GAP_WIDTH;
      for(int i=0; i<g_nNumberOfElev; i++)   {
         float pos = (buildingLeft * 2 + ELEV_GAP_WIDTH*2) / 2;

         glPushMatrix();
         glTranslatef(pos, elevPos[i], 0.0f);
         glCallList(OBJ_ELEVATOR);

         glPopMatrix();

         buildingLeft += ELEV_GAP_WIDTH *2;
      }


      if(m_bRenderFPS)  drawFPS();

      GLenum err = glGetError();
      if ( err != GL_NO_ERROR ) {
         /*
         * TODO:
         * fprintf(stderr, "GLGETERROR=%d\n", (int)err);
         */
      }
   }
コード例 #21
0
/**
 * Zeichen-Callback.
 * Loescht die Buffer, ruft das Zeichnen der Szene auf und tauscht den Front-
 * und Backbuffer.
 */
static void
cbDisplay (void)
{
    int toX = G_fullScreen ? G_Width : G_Width/2,
        toZ = G_fullScreen ? G_Height : G_Height/2;

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glClearColor(0.0, 1.0, 1.0, 0.0);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (!getHelpStatus()) {
        /*==================================================================*/
        /* Textur mit Kamera-Perspektive */
        /*==================================================================*/
        drawSceneToTexture(G_fboCam, getCameraPosition(0), getCameraPosition(1), getCameraPosition(2), 0.0, 0.0, 0.0);

        /*==================================================================*/
        /* Terrain mit Ambient Occlusion. */
        /*==================================================================*/
        glUseProgram(G_ShaderID);
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
            glViewport (0, 0, toX, toZ);
            setProjection (1);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            gluLookAt (getCameraPosition(0), getCameraPosition(1), getCameraPosition(2),
                 0.0, 0.0, 0.0,
                 0.0, 1.0, 0.0);

            glActiveTexture(GL_TEXTURE1);
            glBindTexture(GL_TEXTURE_2D, G_TexCamera);
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, G_TexCameraDepth);

            GLfloat mp[16], mv[16];
            glGetFloatv(GL_PROJECTION_MATRIX, mp);
            glGetFloatv(GL_MODELVIEW_MATRIX, mv);
            glUniformMatrix4fv(glGetUniformLocation(G_ShaderID, "projMatrix"),  1, GL_FALSE, &mp[0]);
            glUniformMatrix4fv(glGetUniformLocation(G_ShaderID, "viewMatrix"),  1, GL_FALSE, &mv[0]);

            glUniform1i(G_sampler2dLoc, 1);
            glUniform1i(G_samplerDepth2dLoc, 0);

            GLuint showTexture[] = {G_showTexture};
            glUniform1iv(glGetUniformLocation(G_ShaderID, "showTexture"), 1, showTexture);
            GLuint screenWidth[] = {G_Width};
            glUniform1iv(glGetUniformLocation(G_ShaderID, "screenWidth"), 1, screenWidth);
            GLuint screenHeight[] = {G_Height};
            glUniform1iv(glGetUniformLocation(G_ShaderID, "screenHeight"), 1, screenHeight);

            GLfloat nearPlane[] = {G_NearPlane};
            glUniform1fv(glGetUniformLocation(G_ShaderID, "nearPlane"), 1, nearPlane);
            GLfloat farPlane[] = {G_FarPlane};
            glUniform1fv(glGetUniformLocation(G_ShaderID, "farPlane"), 1, farPlane);

            GLuint range[] = {getRange()};
            glUniform1iv(glGetUniformLocation(G_ShaderID, "range"), 1, range);

            GLuint pixelDistance[] = {getPixelDistance()};
            glUniform1iv(glGetUniformLocation(G_ShaderID, "pixelDistance"), 1, pixelDistance);

            GLfloat multiplier[] = {getMultiplier()};
            glUniform1fv(glGetUniformLocation(G_ShaderID, "multiplier"), 1, multiplier);

            glBindBuffer (GL_ARRAY_BUFFER, G_WaterBuffer);
            glBufferData (GL_ARRAY_BUFFER, sizeof(*getWaterList())*WORLD_SIZE*WORLD_SIZE, getWaterList(), GL_STATIC_DRAW);
            glEnableVertexAttribArray(0);
            glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(GLfloat)+1*sizeof(GLint), 0);

            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, G_WaterBufferIndex);

            /* Wasser. */
            glDrawElements(GL_TRIANGLES, WORLD_SIZE*WORLD_SIZE*2*3, GL_UNSIGNED_INT, 0);

            glDisableVertexAttribArray(0);
            glDisableVertexAttribArray(1);

        glUseProgram(0);
        drawFPS();
        drawAttributes();
    } else {
        printHelp();
    }
    /* Alles fertig. */
    glutSwapBuffers ();
}
コード例 #22
0
ファイル: main.c プロジェクト: manolaz/Wizznic
int main(int argc, char *argv[])
{
  int doScale=0; // 0=Undefined, 1=320x240, -1=OpenGL, >1=SwScale
  char* dumpPack=NULL;
  int state=1; //Game, Menu, Editor, Quit
  int sdlVideoModeFlags = SDL_SWSURFACE;

  #ifdef PSP
    //Note to PSP porter, please test if HW is actually faster, Wizznic does a lot of memory-manipulation in the screen-surface, each call might initiate a full copy back/forth from video memory. Remove comment when read. :)
    sdlVideoModeFlags = (SDL_HWSURFACE | SDL_DOUBLEBUF |SDL_HWACCEL);
    SetupCallbacks();//Callbacks actifs
    scePowerSetClockFrequency(333,333,166);
  #endif

//  #ifdef WIN32
//Redirect stdout to console on windows, so we can see what's going in.
//  FILE *stream;
//  stream = freopen("CON", "w", stdout);
//  #endif

  //Print welcome message
  printf( "Wizznic "VERSION_STRING". GPLv3 or newer Copyleft 2010-2013\n\n");

  //initialize path strings
  initUserPaths();

  //Tell where stuff's at.
  printf("Directories:\n    Settings: %s\n    DLC: %s\n    Highscores: %s\n    Editorlevels: %s\n    Datafiles: %s\n\n", \
                            getConfigDir(), getUsrPackDir(), getHighscoreDir(), getUserLevelDir(), (!strlen(DATADIR))?".":DATADIR);

  //Print the command line parameters
  printf("Command-line parameters:\n"STR_VID_OPTIONS);

  //Quit if user wants help
  if( argc > 1 && ( strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-help")==0 ))
  {
    printf("Please see readme.txt or http://wizznic.org/ for more help.\n");
    return(0);
  }

  //Read settings
  printf("Loading settings...\n");
  initSettings();

  #if defined(WITH_OPENGL)
  //We start by enabling glScaling if it was enabled in settings, it can then be overwritten by command line options.
  if( setting()->glEnable && doScale==0 )
    doScale=-1;
  #endif

  //Set scaling
  setting()->scaleFactor=1.0;

  atexit(SDL_Quit);

  //Init SDL
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER ) <0 )
  {
    printf("SDL_Init failed: %s\n",SDL_GetError());
    return(-1);
  }

  //Setup display
  #if defined (GP2X) || defined (PSP) || defined (WIZ)
  SDL_Surface* screen = SDL_SetVideoMode(SCREENW,SCREENH,16, sdlVideoModeFlags);
  #else
  SDL_Surface* screen=NULL;

  int i;
  for( i=0; i < argc; i++ )
  {
    if( strcmp( argv[i], "-sw" ) == 0 )
    {
      setting()->glEnable=0;
      doScale=0;
      saveSettings();
    } else
    if( strcmp( argv[i], "-gl" ) == 0 )
    {
      setting()->glEnable=1;
      doScale=-1;
      saveSettings();
    } else
    if( strcmp( argv[i], "-z" ) == 0 )
    {
      if( i+1 < argc )
      {
        doScale = atoi( argv[i+1] );
        setting()->glEnable=0;
        i++;
        saveSettings();
      } else {
        printf(" -z requires zoom level ( -z 2 for example ).\n");
        return(1);
      }
    } else
    if( strcmp( argv[i], "-f" ) == 0 )
    {
        setting()->fullScreen=1;
        saveSettings();
    } else
    if( strcmp( argv[i], "-w" ) == 0 )
      {
        setting()->fullScreen=0;
        saveSettings();
    } else if( strcmp( argv[i], "-glheight" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glHeight = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window height to %i.\n", setting()->glHeight);
        saveSettings();
      } else {
        printf(" -glheight requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glwidth" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glWidth = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window width to %i.\n", setting()->glWidth);
        saveSettings();
      } else {
        printf(" -glwidth requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glfilter" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glFilter=atoi(argv[i+1]);
        printf("OpenGL texture filtering set to %s.\n", (setting()->glFilter)?"Smooth":"Off");
        i++;
        saveSettings();
      } else {
        printf("-glfilter requires 0 or 1 as argument.\n");
        return(1);
      }
    } else if( strcmp( argv[i] , "-d" ) == 0 )
    {
      if( argc == 3 && i < argc+1 )
      {
        dumpPack = malloc( sizeof(char)*strlen(argv[i+1])+1 );
        strcpy( dumpPack, argv[i+1] );
        doScale=0;
        setting()->glEnable=0;
        i++;
      } else {
        printf("-d requires a packname, and must not be used with other parameters.\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-rift") == 0 )
    {
      setting()->glWidth = 1280;
      setting()->glHeight = 800;
      setting()->glEnable=1;
      setting()->rift=1;
      doScale=-1;
    } else if( i > 0 )
    {
      printf("\nError: Invalid argument '%s', quitting.\n", argv[i]);
      return(1);
    }

  }

  if( setting()->fullScreen )
  {
    sdlVideoModeFlags |= SDL_FULLSCREEN;
  }

  if(doScale)
  {
    //Hardware accelerated scaling
    if( doScale == -1 )
    {
    #ifdef HAVE_ACCELERATION
      printf("Enabling platform specific accelerated scaling.\n");
      screen = platformInitAccel(sdlVideoModeFlags);
      if( !screen )
      {
        printf("Failed to set platform accelerated scaling, falling back to software window.\n");
        screen=swScreen(SDL_SWSURFACE);
        doScale=0;
      }
    #else
      printf("\nError:\n  Not compiled with hardware-scaling support, don't give me -z -1\n  Exiting...\n");
      return(-1);
    #endif
    } else if( doScale > 0 )
    {
    #ifdef WANT_SWSCALE
      //Set up software scaling
      printf("Enabling slow software-based scaling to %ix%i.\n",320*doScale, 240*doScale);
      screen = swScaleInit(sdlVideoModeFlags,doScale);
    #else
      printf("\nError:\n  I don't support software scaling, don't give me any -z options\n  Exiting...\n");
      return(-1);
    #endif
    }
  } else {
    screen=swScreen(sdlVideoModeFlags);
    doScale=0;
  }

  printf("Scaling factor: %f\n", setting()->scaleFactor);

  if( screen == NULL )
  {
    printf("ERROR: Couldn't init video.\n");
    return(-1);
  }


  //Set window title
  SDL_WM_SetCaption("Wizznic!", "Wizznic!");
  //Set window icon
  SDL_Surface* icon = IMG_Load( DATADIR"data/wmicon.png");
  SDL_WM_SetIcon(icon, NULL);
  SDL_FreeSurface(icon);

  #endif

  setting()->bpp = screen->format->BytesPerPixel;
  setAlphaCol( setting()->bpp );

  printf("Screen surface using %i bytes per pixel.\n",setting()->bpp);

  //Open Joysticks (for wiz)
  if (SDL_NumJoysticks() > 0) SDL_JoystickOpen(0);

  //Hide mouse cursor
  SDL_ShowCursor(SDL_DISABLE);

  //Load fonts
  txtInit();

  //Load sounds
  if(!initSound())
  {
    printf("Couldn't init sound.\n");
    return(-1);
  }

  //Menu Graphics
  if(!initMenu(screen))
  {
    printf("Couldn't load menu graphics.\n");
    return(-1);
  }

  //Init controls
  initControls();

  //Init stats
  statsInit();

  //Init packs
  packInit();

  //Scan userlevels dir
  makeUserLevelList(screen);

  //Init particles
  initParticles(screen);

  //Seed the pseudo random number generator (for particles 'n' stuff)
  srand( (int)time(NULL) );

  #if defined(PC)
  //Need to dump level-screenshots?
  if(dumpPack)
  {
    printf("Dumping level-images for pack: %s\n", dumpPack);
    dumplevelimages(screen, dumpPack, 0);
    return(0);
  }
  #endif

  //init starfield
  initStars(screen);

  //Init pointer
  initPointer(screen);

  printf("Applying settings..\n");
  //Apply settings (has to be done after packs are inited)
  applySettings();
  //Set Pack
  packSetByPath( setting()->packDir );

  #if defined( PLATFORM_SUPPORTS_STATSUPLOAD )
  if( (setting()->uploadStats) && !(setting()->firstRun) )
  {
    statsUpload(0,0,0,0,0,"check",1, &(setting()->session) );
    statsUpload(0,0,0,0,0,"q_solved",1, &(setting()->solvedWorldWide) );

    //DLC only works when stats-uploading is enabled so we can use the same nag-screen.
    dlcCheckOnline();
  }
  #endif

  printf("Setting Music...\n");
  //Start playing music (has to be done after readong settings)
  soundSetMusic();

  //Initialize credits
  initCredits(screen);

  initTransition();


#if SCREENW != 320 || SCREENH != 240
  SDL_Rect *borderSrcRect = malloc(sizeof(SDL_Rect));
  SDL_Surface* border = loadImg( BORDER_IMAGE );
  if( border )
  {
    printf("Border image loaded.\n");
    borderSrcRect->x=(border->w-SCREENW)/2;
    borderSrcRect->y=(border->h-SCREENH)/2;
    borderSrcRect->w=SCREENW;
    borderSrcRect->h=SCREENH;
    SDL_BlitSurface( border, borderSrcRect, screen, NULL );
    SDL_FreeSurface(border);
  } else {
    printf("Could not load border image: %s\n", BORDER_IMAGE);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
  }
  free(borderSrcRect);
  borderSrcRect=NULL;

#endif

  int lastTick;
  while(state!=STATEQUIT)
  {
    lastTick=SDL_GetTicks();

    frameStart();

    if(runControls()) state=STATEQUIT;
    switch(state)
    {
      case STATEPLAY:
        state = runGame(screen);
      break;

      case STATEMENU:
        state = runMenu(screen);
      break;

      case STATEEDIT:
        state=runEditor(screen);
      break;
    }

    drawPointer(screen);

    soundRun(screen,state);

    runTransition(screen);

    if(setting()->showFps)
      drawFPS(screen);

    switch( doScale )
    {
      #if defined(HAVE_ACCELERATION)
      case -1:
        platformDrawScaled(screen);
        break;
      #endif
      case 0:
        SDL_Flip(screen);
        break;
      #if defined(WANT_SWSCALE)
      default:
        swScale(screen,doScale);
        break;
      #else
      default:
        state=STATEQUIT;
      break;
      #endif
    }

    #if defined(CRUDE_TIMING)
    //Oh how I loathe this, is there no better way?
    while(SDL_GetTicks()-lastTick <= PLATFORM_CRUDE_TIMING_TICKS)
    {
      //Burn, burn baby burn!
    }
    #else
    int t=SDL_GetTicks()-lastTick;
    if(t < 20)
    {
      SDL_Delay( 20 -t);
    }
    #endif
  }

  #if defined(PLATFORM_NEEDS_EXIT)
  platformExit();
  #endif

  SDL_Quit();

  return(0);
}
コード例 #23
0
ファイル: cgameboard.cpp プロジェクト: oktal/Bombermelee
/**
  Function called to refresh the view on canvas
*/
void CGameBoard::OnUpdate()
{
    Clear(sf::Color(195, 195, 195)); /* Grey */
    sf::Shape rightBorder = sf::Shape::Rectangle(510, 0, 630, 510, sf::Color(127, 127, 127));
    Draw(rightBorder);

    if (m_fpsRefreshTime.GetElapsedTime() >= 1.0f)
    {
        m_frameRate = 1.f / GetFrameTime();
        m_fpsRefreshTime.Reset();
    }
    drawMap();
    drawFPS();
    drawStatus();
    drawExplosions();
    drawPlayers();
    drawBonusCanvas();

    if (!m_gameBegin || !m_connected)
    {
        return;
    }

    /* Handling Event */
    CPlayer *me = m_playersList[0]; /* I am the first player of the list */
    float x = me->GetPosition().x;
    float y = me->GetPosition().y;
    std::string pos = QString("%1 %2").arg(me->GetPosition().x).arg(me->GetPosition().y)
                                      .toStdString();
    if (me->isDead())
    {
        return;
    }

    sf::Event event;
    while (GetEvent(event))
    {
        switch (event.Type)
        {
        case sf::Event::KeyPressed:
            if (event.Key.Code == sf::Key::Space)
            {
                plantBomb();
            }
            else if (event.Key.Code == sf::Key::E)
            {
                useSpecialBonus();
            }
            break;
        default:
            break;
        }
    }


    if (GetInput().IsKeyDown(sf::Key::Right) ||
        GetInput().IsKeyDown(sf::Key::D))
    {
        switch (me->getCollision(Right, m_map))
        {
        case Floor:
        case Bonus:
            if (me->getDirection() != Right)
            {
                m_networkManager->sendMovePacket(me->getNick(), Right, x, y);
                me->setDirection(Right);
            }
            break;
        case Bomb:
            if (me->getBonus(CBonus::BombPass) != NULL)
            {
                me->setDirection(Right);
            }
            else if (me->getBonus(CBonus::BombKick) != NULL)
            {
                QList<CBomb *>::iterator it;
                for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                {
                    CBomb *bomb = *it;
                    if (bomb->getX() == me->getX() + 1 && bomb->getY() == me->getY())
                    {
                        bomb->setDirection(CBomb::Right);
                        m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                        break;
                    }
                }
            }
            break;
        default:
            break;
        }

        if (me->IsPaused())
        {
            me->Play();
        }
    }
     else if (GetInput().IsKeyDown(sf::Key::Left) ||
              GetInput().IsKeyDown(sf::Key::Q))
     {
         switch (me->getCollision(Left, m_map))
         {
         case Floor:
         case Bonus:
              if (me->getDirection() != Left)
              {
                  me->setDirection(Left);
                  m_networkManager->sendMovePacket(me->getNick(), Left, x, y);
              }
              break;
         case Bomb:
              if (me->getBonus(CBonus::BombPass) != NULL)
              {
                  me->setDirection(Left);
              }
              else if (me->getBonus(CBonus::BombKick) != NULL)
              {
                  QList<CBomb *>::iterator it;
                  for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                  {
                      CBomb *bomb = *it;
                      if (bomb->getX() == me->getX() - 1 && bomb->getY() == me->getY())
                      {
                          bomb->setDirection(CBomb::Left);
                          m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                          break;
                      }
                  }
              }
              break;
         default:
              break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }
     }
     else if (GetInput().IsKeyDown(sf::Key::Down) ||
              GetInput().IsKeyDown(sf::Key::S))
     {
         switch (me->getCollision(Down, m_map))
         {
         case Floor:
         case Bonus:
             if (me->getDirection() != Down)
              {
                   me->setDirection(Down);
                   m_networkManager->sendMovePacket(me->getNick(), Down, x, y);
              }
             else if (me->getBonus(CBonus::BombKick) != NULL)
             {
                 QList<CBomb *>::iterator it;
                 for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                 {
                     CBomb *bomb = *it;
                     if (bomb->getX() == me->getX() && bomb->getY() == me->getY() + 1)
                     {
                         bomb->setDirection(CBomb::Down);
                         m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                         break;
                     }
                 }
             }
             break;
         case Bomb:
             if (me->getBonus(CBonus::BombPass) != NULL)
             {
                 me->setDirection(Down);
             }
             break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else if (GetInput().IsKeyDown(sf::Key::Up) ||
              GetInput().IsKeyDown(sf::Key::Z))
     {
         switch (me->getCollision(Up, m_map))
         {
         case Floor:
         case Bonus:
               if (me->getDirection() != Up)
               {
                    m_networkManager->sendMovePacket(me->getNick(), Up, x, y);
                    me->setDirection(Up);
               }
               break;
         case Bomb:
               if (me->getBonus(CBonus::BombPass) != NULL)
               {
                   me->setDirection(Up);
               }
               else if (me->getBonus(CBonus::BombKick) != NULL)
               {
                   QList<CBomb *>::iterator it;
                   for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                   {
                       CBomb *bomb = *it;
                       if (bomb->getX() == me->getX() && bomb->getY() == me->getY() - 1)
                       {
                           bomb->setDirection(CBomb::Up);
                           m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                           break;
                       }
                   }
               }
               break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else
     {
         if (me->getDirection() != Stopped && me->getElapsedTime() >= me->getStopTime())
         {
             me->setDirection(Stopped);
             m_networkManager->sendMovePacket(me->getNick(), Stopped, x, y);
             me->Pause();
         }
     }
}