Beispiel #1
0
void TileMap::Render( int OffsetX, int OffsetY, float Scale )
{
	Render( OffsetX, OffsetY, Scale, Scale );
}
// the program starts here
void MainApplication() {
    // initialise GLFW
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");

    // open a window with GLFW
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
    MainWindow = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y,"Rotation",NULL,NULL);
    if(!MainWindow)
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 4.2?");

    glfwSetWindowSizeCallback(MainWindow,handleResize); //callback function of GLFW to handle window resize
    glfwSetKeyCallback(MainWindow,handleKeypress); //callback function to handle keypress

    glfwMakeContextCurrent(MainWindow);

    // initialise GLEW
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");

    // print out some info about the graphics drivers
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    // make sure OpenGL version 3.2 API is available
    if(!GLEW_VERSION_4_2)
        throw std::runtime_error("OpenGL 4.2 API is not available.");

    // load vertex and fragment shaders into opengl
    LoadShaders();

    // create buffer and fill it with the points of the triangle
    LoadTriangle();

    // run while the window is open
    double lastTime = glfwGetTime();
    while(!glfwWindowShouldClose(MainWindow)){
    // update the scene based on the time elapsed since last update
        double thisTime = glfwGetTime();
        Update(thisTime - lastTime);
        lastTime = thisTime;

        // process pending events
        glfwPollEvents();

        // draw one frame
        Render(MainWindow);

        // check for errors
        GLenum error = glGetError();
        if(error != GL_NO_ERROR)
            std::cerr << "OpenGL Error " << error /*<< ": " << (const GLubyte)gluErrorString(error)*/ << std::endl;
    }

    // clean up and exit
    glfwTerminate();
}
//*************************************************************************************************************
int main(int argc, char* argv[])
{
	ReadResolutionFile();

	LARGE_INTEGER qwTicksPerSec = { 0, 0 };
	LARGE_INTEGER qwTime;
	LONGLONG tickspersec;
	double last, current;
	double delta, accum = 0;

	WNDCLASSEX wc =
	{
		sizeof(WNDCLASSEX),
		CS_OWNDC,
		(WNDPROC)WndProc,
		0L,
		0L,
		GetModuleHandle(NULL),
		NULL,
		LoadCursor(0, IDC_ARROW),
		NULL, NULL, "TestClass", NULL
	};

	RegisterClassEx(&wc);
	SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);

	RECT rect = { 0, 0, screenwidth, screenheight };
	DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS;

	// windowed mode
	style |= WS_SYSMENU|WS_BORDER|WS_CAPTION;
	Adjust(rect, screenwidth, screenheight, style, 0);

	hwnd = CreateWindowA("TestClass", TITLE, style,
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
		NULL, NULL, wc.hInstance, NULL);

	if( !hwnd )
	{
		MYERROR("Could not create window");
		goto _end;
	}

	if( FAILED(InitDirect3D(hwnd)) )
	{
		MYERROR("Failed to initialize Direct3D");
		goto _end;
	}
	
	if( FAILED(InitScene()) )
	{
		MYERROR("Failed to initialize scene");
		goto _end;
	}

	ShowWindow(hwnd, SW_SHOWDEFAULT);
	UpdateWindow(hwnd);

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	POINT p;
	GetCursorPos(&p);
	ScreenToClient(hwnd, &p);

	// timer
	QueryPerformanceFrequency(&qwTicksPerSec);
	tickspersec = qwTicksPerSec.QuadPart;

	QueryPerformanceCounter(&qwTime);
	last = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

	while( msg.message != WM_QUIT )
	{
		QueryPerformanceCounter(&qwTime);

		current = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

		if (current < last)
			delta = ((1.0 + current) - last);
		else
			delta = (current - last);

		last = current;
		accum += delta;

		mousedx = mousedy = 0;

		while( accum > 0.0333f )
		{
			accum -= 0.0333f;

			while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) )
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

			Update(0.0333f);
		}

		if( msg.message != WM_QUIT )
			Render((float)accum / 0.0333f, (float)delta);
	}

_end:
	UninitScene();

	if( device )
	{
		ULONG rc = device->Release();

		if( rc > 0 )
			MYERROR("You forgot to release something");
	}

	if( direct3d )
		direct3d->Release();

	UnregisterClass("TestClass", wc.hInstance);
	_CrtDumpMemoryLeaks();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}
Beispiel #4
0
void ALSoftwareGraphicsDriver::Render()
{
    Render(None);
}
Beispiel #5
0
/* Function that runs the application */
INT CXBApplicationEx::Run()
{
  CLog::Log(LOGNOTICE, "Running the application..." );

  unsigned int lastFrameTime = 0;
  unsigned int frameTime = 0;
  const unsigned int noRenderFrameTime = 15;  // Simulates ~66fps

#ifdef XBMC_TRACK_EXCEPTIONS
  BYTE processExceptionCount = 0;
  BYTE frameMoveExceptionCount = 0;
  BYTE renderExceptionCount = 0;
  const BYTE MAX_EXCEPTION_COUNT = 10;
#endif

  // Run xbmc
  while (!m_bStop)
  {
#ifdef HAS_PERFORMANCE_SAMPLE
    CPerformanceSample sampleLoop("XBApplicationEx-loop");
#endif
    //-----------------------------------------
    // Animate and render a frame
    //-----------------------------------------
#ifdef XBMC_TRACK_EXCEPTIONS
    try
    {
#endif
      lastFrameTime = XbmcThreads::SystemClockMillis();
      Process();
      //reset exception count
#ifdef XBMC_TRACK_EXCEPTIONS
      processExceptionCount = 0;

    }
    catch (const XbmcCommons::UncheckedException &e)
    {
      e.LogThrowMessage("CApplication::Process()");
      processExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (processExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
        throw;
      }
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "exception in CApplication::Process()");
      processExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (processExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
        throw;
      }
    }
#endif
    // Frame move the scene
#ifdef XBMC_TRACK_EXCEPTIONS
    try
    {
#endif
      if (!m_bStop) FrameMove(true, m_renderGUI);
      //reset exception count
#ifdef XBMC_TRACK_EXCEPTIONS
      frameMoveExceptionCount = 0;

    }
    catch (const XbmcCommons::UncheckedException &e)
    {
      e.LogThrowMessage("CApplication::FrameMove()");
      frameMoveExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (frameMoveExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::FrameMove(), too many exceptions");
        throw;
      }
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "exception in CApplication::FrameMove()");
      frameMoveExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (frameMoveExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::FrameMove(), too many exceptions");
        throw;
      }
    }
#endif

    // Render the scene
#ifdef XBMC_TRACK_EXCEPTIONS
    try
    {
#endif
      if (m_renderGUI && !m_bStop) Render();
      else if (!m_renderGUI)
      {
        frameTime = XbmcThreads::SystemClockMillis() - lastFrameTime;
        if(frameTime < noRenderFrameTime)
          Sleep(noRenderFrameTime - frameTime);
      }
#ifdef XBMC_TRACK_EXCEPTIONS
      //reset exception count
      renderExceptionCount = 0;

    }
    catch (const XbmcCommons::UncheckedException &e)
    {
      e.LogThrowMessage("CApplication::Render()");
      renderExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (renderExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::Render(), too many exceptions");
        throw;
      }
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "exception in CApplication::Render()");
      renderExceptionCount++;
      //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
      if (renderExceptionCount > MAX_EXCEPTION_COUNT)
      {
        CLog::Log(LOGERROR, "CApplication::Render(), too many exceptions");
        throw;
      }
    }
#endif
  } // while (!m_bStop)
  Destroy();

  CLog::Log(LOGNOTICE, "application stopped..." );
  return m_ExitCode;
}
Beispiel #6
0
void BaseScene::RenderFrame() {
	SDL_FillRect(screen, 0, 0);
	Render(screen);
	SDL_Flip(screen);
}
Beispiel #7
0
int WorldClass::Tick()
{
    Update(CheckInput());
    Render();
    return 1;
}
Beispiel #8
0
void Texture::Render(SDL_Renderer *const Renderer, const int &x, const int &y)
{
	return Render(Renderer, x, y, NULL, 0.0, NULL, SDL_RendererFlip());
}
Beispiel #9
0
void Texture::Render(SDL_Renderer *const Renderer, const int &x, const int &y, const SDL_RendererFlip &Flip)
{
	return Render(Renderer, x, y, NULL, 0.0, NULL, Flip);
}
Beispiel #10
0
void Texture::Render(SDL_Renderer *const Renderer, const int &x, const int &y, const double &Angle, SDL_Point *const Centre, const SDL_RendererFlip &Flip)
{
	return Render(Renderer, x, y, NULL, Angle, Centre, Flip);
}
Beispiel #11
0
void Texture::Render(SDL_Renderer *const Renderer, const int &x, const int &y, SDL_Rect *const Clip, const double &Angle, SDL_Point *const Centre)
{
	return Render(Renderer, x, y, Clip, Angle, Centre, SDL_RendererFlip());
}
Beispiel #12
0
void hgeFont::printfb(const float x, const float y, const float w, const float h,
                      const int align, const char* format, ...) {
    auto lines = 0;
    const auto p_arg = reinterpret_cast<char *>(&format) + sizeof(format);

    _vsnprintf(buffer_, sizeof(buffer_) - 1, format, p_arg);
    buffer_[sizeof(buffer_) - 1] = 0;
    //vsprintf(buffer, format, pArg);

    char* linestart = buffer_;
    char* pbuf = buffer_;
    char* prevword = nullptr;

    for (;;) {
        int i = 0;
        while (pbuf[i] && pbuf[i] != ' ' && pbuf[i] != '\n') {
            i++;
        }

        const auto chr = pbuf[i];
        pbuf[i] = 0;
        const auto ww = GetStringWidth(linestart);
        pbuf[i] = chr;

        if (ww > w) {
            if (pbuf == linestart) {
                pbuf[i] = '\n';
                linestart = &pbuf[i + 1];
            }
            else {
                *prevword = '\n';
                linestart = prevword + 1;
            }

            lines++;
        }

        if (pbuf[i] == '\n') {
            prevword = &pbuf[i];
            linestart = &pbuf[i + 1];
            pbuf = &pbuf[i + 1];
            lines++;
            continue;
        }

        if (!pbuf[i]) {
            lines++;
            break;
        }

        prevword = &pbuf[i];
        pbuf = &pbuf[i + 1];
    }

    auto tx = x;
    auto ty = y;
    const auto hh = height_ * spacing_ * scale_ * lines;

    switch (align & HGETEXT_HORZMASK) {
    case HGETEXT_LEFT:
        break;
    case HGETEXT_RIGHT:
        tx += w;
        break;
    case HGETEXT_CENTER:
        tx += int(w / 2);
        break;
    }

    switch (align & HGETEXT_VERTMASK) {
    case HGETEXT_TOP:
        break;
    case HGETEXT_BOTTOM:
        ty += h - hh;
        break;
    case HGETEXT_MIDDLE:
        ty += int((h - hh) / 2);
        break;
    }

    Render(tx, ty, align, buffer_);
}
Beispiel #13
0
// From <https://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_GLX_and_Xlib>
int main(int argc, char** argv){
 Initialised = false;
 StartTime   = GetClock();

 double time;

 Display*             dpy;
 Window               root;
 XVisualInfo*         vi;
 Colormap             cmap;
 XSetWindowAttributes swa;
 Window               win;
 GLXContext           glc;
 XWindowAttributes    gwa;
 XEvent               xev;

 GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};

 dpy = XOpenDisplay(0);

 if(dpy == 0){
  printf("\n\tcannot connect to X server\n\n");
  return 1;
 }

 root = DefaultRootWindow(dpy);

 vi = glXChooseVisual(dpy, 0, att);

 if(vi == 0){
  printf("\n\tno appropriate visual found\n\n");
  return 1;
 }else{
  // %p creates hexadecimal output like in glxinfo
  printf("\n\tvisual %p selected\n", (void*)vi->visualid);
 }

 cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);

 swa.colormap = cmap;
 swa.event_mask = ExposureMask | KeyPressMask;

 win = XCreateWindow(
  dpy,
  root,
  0, 0, 640, 480, 0,
  vi->depth,
  InputOutput,
  vi->visual,
  CWColormap | CWEventMask,
  &swa
 );

 XMapWindow(dpy, win);
 XStoreName(dpy, win, "OpenGL Sample");

 glc = glXCreateContext(dpy, vi, 0, GL_TRUE);
 glXMakeCurrent(dpy, win, glc);

 if(!InitGLEW()){
  glXMakeCurrent   (dpy, None, 0);
  glXDestroyContext(dpy, glc);
  XDestroyWindow   (dpy, win);
  XCloseDisplay    (dpy);
  return 1;
 }
 if(!LoadShader ("OpenGL/Texture.vp", "OpenGL/Texture.fp")) return 1;
 if(!LoadTexture("Pic/greatwall.jpg")) return 1;
 Initialised = true;

 bool running = true;
 while(running){
  while(XCheckWindowEvent(dpy, win, 0xFFFFFFFF, &xev)){
   switch(xev.type){
    case Expose:
     XGetWindowAttributes(dpy, win, &gwa);
     Render(gwa.width, gwa.height);
     glXSwapBuffers(dpy, win);
     break;

    case KeyPress:
     // printf("KeyPress: keycode %u state %u\n", xev.xkey.keycode, xev.xkey.state);
     if(xev.xkey.keycode == Key_Escape) running = false;
     else OnKeyDown(xev.xkey.keycode);
     break;
   }
  }
  XGetWindowAttributes(dpy, win, &gwa);
  Render(gwa.width, gwa.height);
  glXSwapBuffers(dpy, win);
  RenderTime(GetClock()-time);
  time = GetClock();
  usleep(1000);
 }
 glXMakeCurrent   (dpy, None, 0);
 glXDestroyContext(dpy, glc);
 XDestroyWindow   (dpy, win);
 XCloseDisplay    (dpy);

 free(InputBuffer );
 free(OutputBuffer);

 return 0;
}
Beispiel #14
0
int WINAPI WinMain(
 HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR     lpCmdLine,
 int       nCmdShow
){
 Initialised = false;
 StartTime   = GetClock();

 double time = StartTime;

 WNDCLASSEX wcex;
 HGLRC      hRC;
 RECT       rect;
 MSG        msg;

 // register window class
 wcex.cbSize        = sizeof(WNDCLASSEX);
 wcex.style         = CS_OWNDC;
 wcex.lpfnWndProc   = WndProc;
 wcex.cbClsExtra    = 0;
 wcex.cbWndExtra    = 0;
 wcex.hInstance     = hInstance;
 wcex.hIcon         = LoadIcon(0, IDI_APPLICATION);
 wcex.hCursor       = LoadCursor(0, IDC_ARROW);
 wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
 wcex.lpszMenuName  = 0;
 wcex.lpszClassName = "GLSample";
 wcex.hIconSm       = LoadIcon(0, IDI_APPLICATION);;

 if(!RegisterClassEx(&wcex)) return 0;

 // create main window
 hwnd = CreateWindowEx(
  0,
  "GLSample",
  "OpenGL Sample",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, CW_USEDEFAULT,
  640, 480,
  0,
  0,
  hInstance,
  0
 );

 ShowWindow(hwnd, nCmdShow);

 // enable OpenGL for the window
 PIXELFORMATDESCRIPTOR pfd;

 int iFormat;

 // get the device context (DC)
 hDC = GetDC(hwnd);

 // set the pixel format for the DC
 ZeroMemory(&pfd, sizeof(pfd));

 pfd.nSize      = sizeof(pfd);
 pfd.nVersion   = 1;
 pfd.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 pfd.iPixelType = PFD_TYPE_RGBA;
 pfd.cColorBits = 24;
 pfd.cDepthBits = 0;
 pfd.iLayerType = PFD_MAIN_PLANE;

 iFormat = ChoosePixelFormat(hDC, &pfd);

 SetPixelFormat(hDC, iFormat, &pfd);

 // create and enable the render context (RC)
 hRC = wglCreateContext(hDC);

 wglMakeCurrent(hDC, hRC);

 if(!InitGLEW()){
  wglMakeCurrent(0, 0);
  wglDeleteContext(hRC);
  ReleaseDC(hwnd, hDC);
  DestroyWindow(hwnd);
  return 1;
 }
 if(!LoadShader ("..\\OpenGL\\Texture.vp", "..\\OpenGL\\Texture.fp")) return 1;
 if(!LoadTexture("..\\Pic\\greatwall.jpg")) return 1;
 Initialised = true;

 Initialised = true;

 // program main loop
 while(true){
  while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){
   if(msg.message == WM_QUIT) break;
   TranslateMessage(&msg);
   DispatchMessage (&msg);
  }
  if(msg.message == WM_QUIT) break;

  GetClientRect(hwnd, &rect);
  Render(rect.right, rect.bottom);
  SwapBuffers(hDC);
  RenderTime(GetClock()-time);
  time = GetClock();
  Sleep(1);
 }
 wglMakeCurrent(0, 0);
 wglDeleteContext(hRC);
 ReleaseDC(hwnd, hDC);
 DestroyWindow(hwnd);

 free(InputBuffer );
 free(OutputBuffer);

 return msg.wParam;
}
Beispiel #15
0
void GameStart() {
	RenderWindow window(VideoMode(MapWidth * SpriteSize, MapHeight * SpriteSize), "Snake");
	Clock clock;
	Game* game;
	NewGame(game);
	Text text = game->game_text->text;

	while (window.isOpen()) //разбить на 3 метода
	{
		float time = clock.getElapsedTime().asSeconds();
		clock.restart();
		game->consts->time_counter += time;

		ProcessEvents(window, game);

		if (game->state == STARTGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Snake!\n\nPress 'U' to start!");
			text.setPosition(250, 50);
			window.draw(text);
		}
		else if (game->state == RESTART) {
			DestroyGame(game);
			NewGame(game);
			text = game->game_text->text;
			game->state = PLAY;
		}
		else if (game->state == PAUSE) {
			window.clear();
			Render(window, game);
			text.setCharacterSize(150);
			text.setString("Pause");
			text.setPosition(455, 160);
			window.draw(text);
		}
		else if (game->state == PLAY) {
			while (game->consts->time_counter > game->consts->speed) {
				game->consts->time_counter = 0;

				//Snake movement

				Step(game->snake);

				int snake_draw_counter = SnakeLength(game->snake);

				ProcessCollisions(snake_draw_counter, game);
			}
			Render(window, game);
		}
		else if (game->state == ENDGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Score: " + ToString(game->consts->score) + "\n Press 'Esc' to exit\n Press 'R' to restart");
			text.setPosition(170, 28);
			window.draw(text);
		}

		window.display();
	}
	DestroyGame(game);
}
void ClassDemoApp::UpdateAndRender() {
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
			done = true;
		}
		else if (false && event.type == SDL_MOUSEBUTTONDOWN && state == PlayingLevel) {	//debugging - moves player(s) to cursor
			if (event.button.button == SDL_BUTTON_LEFT) {
				if (!includePlayer2) {
					player->x += (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player->y -= (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player->velocity_y = 0;
				}
				else {
					player->x = (player->x + player2->x) / 2 + (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player->y = (player->y + player2->y) / 2 - (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player->velocity_y = 0;
				}
			}
			else if (event.button.button == SDL_BUTTON_RIGHT) {
				if (includePlayer2) {
					player2->x = (player->x + player2->x) / 2 + (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player2->y = (player->y + player2->y) / 2 - (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player2->velocity_y = 0;
				}
			}
		}
		else if (event.type == SDL_KEYDOWN) {
			if (event.key.keysym.scancode == SDL_SCANCODE_R) {
				infoBoxTimer = 8;
				ResetPos();
			}
			else {
				infoBoxTimer *= 0.05f;
				if (!includePlayer2 && (event.key.keysym.scancode == controls[1]->UP ||
					event.key.keysym.scancode == controls[1]->DOWN ||
					event.key.keysym.scancode == controls[1]->LEFT ||
					event.key.keysym.scancode == controls[1]->RIGHT ||
					event.key.keysym.scancode == controls[1]->EXTEND)) {
					includePlayer2 = true;
					entities.push_back(player2);
				}
			}
		}
	}

	float ticks = (float)SDL_GetTicks() / 1000.0f;
	float elapsed = ticks - lastElapsedTime;
	lastElapsedTime = ticks;

	float fixedElapsed = elapsed;
	if (fixedElapsed > FIXED_TIMESTEP * MAX_TIMESTEP)
		fixedElapsed = FIXED_TIMESTEP * MAX_TIMESTEP;
	while (fixedElapsed > FIXED_TIMESTEP) {
		fixedElapsed -= FIXED_TIMESTEP;
		Update(FIXED_TIMESTEP);
	}
	Update(fixedElapsed);

	infoBoxTimer -= elapsed;
	movingColor += elapsed * 0.3f;
	Render();
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
    int fsaa, accel;
    int value;
    int i, done;
    SDL_DisplayMode mode;
    SDL_Event event;
    Uint32 then, now, frames;
    int status;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Initialize parameters */
    fsaa = 0;
    accel = 0;

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }
    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
                ++fsaa;
                consumed = 1;
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
                ++accel;
                consumed = 1;
            } else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
                i++;
                if (!argv[i]) {
                    consumed = -1;
                } else {
                    depth = SDL_atoi(argv[i]);
                    consumed = 1;
                }
            } else {
                consumed = -1;
            }
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
                    SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }

    /* Set OpenGL parameters */
    state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
    state->gl_red_size = 5;
    state->gl_green_size = 5;
    state->gl_blue_size = 5;
    state->gl_depth_size = depth;
    state->gl_major_version = 1;
    state->gl_minor_version = 1;
    state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    if (fsaa) {
        state->gl_multisamplebuffers=1;
        state->gl_multisamplesamples=fsaa;
    }
    if (accel) {
        state->gl_accelerated=1;
    }
    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(context));
    if (context == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
        quit(2);
    }

    /* Create OpenGL ES contexts */
    for (i = 0; i < state->num_windows; i++) {
        context[i] = SDL_GL_CreateContext(state->windows[i]);
        if (!context[i]) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
            quit(2);
        }
    }

    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
        SDL_GL_SetSwapInterval(1);
    } else {
        SDL_GL_SetSwapInterval(0);
    }

    SDL_GetCurrentDisplayMode(0, &mode);
    SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
    SDL_Log("\n");
    SDL_Log("Vendor     : %s\n", glGetString(GL_VENDOR));
    SDL_Log("Renderer   : %s\n", glGetString(GL_RENDERER));
    SDL_Log("Version    : %s\n", glGetString(GL_VERSION));
    SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
    SDL_Log("\n");

    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
                SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
                SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
                SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
                SDL_GetError());
    }
    if (fsaa) {
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
        if (!status) {
            SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
                    SDL_GetError());
        }
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
        if (!status) {
            SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
                   value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
                    SDL_GetError());
        }
    }
    if (accel) {
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
        if (!status) {
            SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
                    SDL_GetError());
        }
    }

    /* Set rendering settings for each context */
    for (i = 0; i < state->num_windows; ++i) {
        float aspectAdjust;

        status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
        if (status) {
            SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());

            /* Continue for next window */
            continue;
        }

        aspectAdjust = (4.0f / 3.0f) / ((float)state->window_w / state->window_h);
        glViewport(0, 0, state->window_w, state->window_h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrthof(-2.0, 2.0, -2.0 * aspectAdjust, 2.0 * aspectAdjust, -20.0, 20.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glShadeModel(GL_SMOOTH);
    }

    /* Main render loop */
    frames = 0;
    then = SDL_GetTicks();
    done = 0;
    while (!done) {
        /* Check for events */
        ++frames;
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_WINDOWEVENT:
                switch (event.window.event) {
                    case SDL_WINDOWEVENT_RESIZED:
                        for (i = 0; i < state->num_windows; ++i) {
                            if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
                                status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
                                if (status) {
                                    SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
                                    break;
                                }
                                /* Change view port to the new window dimensions */
                                glViewport(0, 0, event.window.data1, event.window.data2);
                                /* Update window content */
                                Render();
                                SDL_GL_SwapWindow(state->windows[i]);
                                break;
                            }
                        }
                        break;
                }
            }
            SDLTest_CommonEvent(state, &event, &done);
        }
        for (i = 0; i < state->num_windows; ++i) {
            if (state->windows[i] == NULL)
                continue;
            status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
            if (status) {
                SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());

                /* Continue for next window */
                continue;
            }
            Render();
            SDL_GL_SwapWindow(state->windows[i]);
        }
    }

    /* Print out some timing information */
    now = SDL_GetTicks();
    if (now > then) {
        SDL_Log("%2.2f frames per second\n",
               ((double) frames * 1000) / (now - then));
    }
#if !defined(__ANDROID__)
    quit(0);
#endif        
    return 0;
}
Beispiel #18
0
Buffer WoWFile::getFileBuff(){
	Render();
	this->buff.setPosition(0);
	return this->buff;
}
Beispiel #19
0
int
main(int argc, char *argv[])
{
    int fsaa, accel;
    int value;
    int i, done;
    SDL_DisplayMode mode;
    SDL_Event event;
    Uint32 then, now, frames;
    int status;
    int dw, dh;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Initialize parameters */
    fsaa = 0;
    accel = -1;

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }
    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
                fsaa = atoi(argv[i+1]);
                consumed = 2;
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
                accel = atoi(argv[i+1]);
                consumed = 2;
            } else {
                consumed = -1;
            }
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
                    SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }

    /* Set OpenGL parameters */
    state->window_flags |= SDL_WINDOW_OPENGL;
    state->gl_red_size = 5;
    state->gl_green_size = 5;
    state->gl_blue_size = 5;
    state->gl_depth_size = 16;
    state->gl_double_buffer = 1;
    if (fsaa) {
        state->gl_multisamplebuffers = 1;
        state->gl_multisamplesamples = fsaa;
    }
    if (accel >= 0) {
        state->gl_accelerated = accel;
    }

    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    /* Create OpenGL context */
    context = SDL_GL_CreateContext(state->windows[0]);
    if (!context) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
        quit(2);
    }
    
    /* Important: call this *after* creating the context */
    if (LoadContext(&ctx) < 0) {
        SDL_Log("Could not load GL functions\n");
        quit(2);
        return 0;
    }

    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
        /* try late-swap-tearing first. If not supported, try normal vsync. */
        if (SDL_GL_SetSwapInterval(-1) == -1) {
            SDL_GL_SetSwapInterval(1);
        }
    } else {
        SDL_GL_SetSwapInterval(0);  /* disable vsync. */
    }

    SDL_GetCurrentDisplayMode(0, &mode);
    SDL_Log("Screen BPP    : %d\n", SDL_BITSPERPIXEL(mode.format));
    SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
    SDL_GetWindowSize(state->windows[0], &dw, &dh);
    SDL_Log("Window Size   : %d,%d\n", dw, dh);
    SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
    SDL_Log("Draw Size     : %d,%d\n", dw, dh);
    SDL_Log("\n");
    SDL_Log("Vendor        : %s\n", glGetString(GL_VENDOR));
    SDL_Log("Renderer      : %s\n", glGetString(GL_RENDERER));
    SDL_Log("Version       : %s\n", glGetString(GL_VERSION));
    SDL_Log("Extensions    : %s\n", glGetString(GL_EXTENSIONS));
    SDL_Log("\n");

    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
    }
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
    if (!status) {
        SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
    } else {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
    }
    if (fsaa) {
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
        if (!status) {
            SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
                   SDL_GetError());
        }
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
        if (!status) {
            SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
                   value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
                   SDL_GetError());
        }
    }
    if (accel >= 0) {
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
        if (!status) {
            SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
                   value);
        } else {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
                   SDL_GetError());
        }
    }

    /* Set rendering settings */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glShadeModel(GL_SMOOTH);
    
    /* Main render loop */
    frames = 0;
    then = SDL_GetTicks();
    done = 0;
    while (!done) {
        /* Check for events */
        ++frames;
        while (SDL_PollEvent(&event)) {
            SDLTest_CommonEvent(state, &event, &done);
        }
        for (i = 0; i < state->num_windows; ++i) {
            int w, h;
            if (state->windows[i] == NULL)
                continue;
            SDL_GL_MakeCurrent(state->windows[i], context);
            SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
            glViewport(0, 0, w, h);
            Render();
            SDL_GL_SwapWindow(state->windows[i]);
        }
    }

    /* Print out some timing information */
    now = SDL_GetTicks();
    if (now > then) {
        SDL_Log("%2.2f frames per second\n",
               ((double) frames * 1000) / (now - then));
    }
    quit(0);
    return 0;
}
// Windows message processing function.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  switch (message) 
  {
  case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_CONNECT:
      DialogBox(hInst, (LPCTSTR)IDD_NATNET, hWnd, (DLGPROC)NatNetDlgProc);
      break;
    case IDM_EXIT:
      DestroyWindow(hWnd);
      break;
    default:
      return DefWindowProc(hWnd, message, wParam, lParam);
    }

    break;

  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // Render a frame NatNet data. This data has been saved off in NatNet callbacks 
    // into the file level variables markerPositions and rigidBodies
    wglMakeCurrent(hdc, openGLRenderContext);
    Render();
    SwapBuffers(hdc);
    wglMakeCurrent(0, 0);
    EndPaint(hWnd, &ps);
    break;

  case WM_SIZE:
    {
      int cx = LOWORD(lParam), cy = HIWORD(lParam);
      if(cx != 0 && cy !=0 && hWnd != nullptr)
      {
        GLfloat fFovy  = 40.0f; // Field-of-view
        GLfloat fZNear = 1.0f;  // Near clipping plane
        GLfloat fZFar = 10000.0f;  // Far clipping plane

        HDC hDC = GetDC(hWnd);
        wglMakeCurrent(hDC, openGLRenderContext);

        // Calculate OpenGL viewport aspect
        RECT rv;
        GetClientRect(hWnd, &rv);
        GLfloat fAspect = (GLfloat)(rv.right-rv.left) / (GLfloat)(rv.bottom-rv.top);

        // Define OpenGL viewport
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(fFovy, fAspect, fZNear, fZFar);
        glViewport(rv.left, rv.top, rv.right-rv.left, rv.bottom-rv.top);
        glMatrixMode(GL_MODELVIEW);

        wglMakeCurrent(0, 0);
        ReleaseDC(hWnd, hDC);
      }
    }
    break;

  case WM_DESTROY:
    {
      HDC hDC = GetDC(hWnd);
      wglMakeCurrent(hDC, openGLRenderContext);
      natnetClient.Uninitialize();
      wglMakeCurrent(0, 0);
      wglDeleteContext(openGLRenderContext);
      ReleaseDC(hWnd, hDC);
      PostQuitMessage(0);
    }
    break;

  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }

  return 0;
}
void HTMLTemplateRenderer::RenderAll(std::ostream &reply, Context &context, const ROAnything &args)
{
	StartTrace(HTMLTemplateRenderer.RenderAll);
	TraceAny(args, "args");
	ROAnything theRendererConfig, roaParserConfig;
	Anything rendererConfig;

	// check if we have special parser configuration to use
	if ( !args.LookupPath(roaParserConfig, "ParserConfig") ) {
		context.Lookup("HTMLTemplateConfig.ParserConfig", roaParserConfig);
	}

	if (args.IsDefined("TemplateName")) {
		String filename;
		Renderer::RenderOnString(filename, context, args["TemplateName"]);
		if (filename.Length() == 0) {
			SystemLog::Error("HTMLTemplateRenderer::RenderAll: cannot find template name");
		} else {
			const char *lang = context.Language();		// cache language flag for localized strings
			TraceAny(fgNameMap, "current cache map");
			String pathUsed = fgNameMap[filename][lang].AsCharPtr("");
			Trace("Template file :" << filename << ";" << pathUsed << ";" << lang );
			if ( pathUsed.Length() > 0 ) { // we got the filekey
				theRendererConfig = fgTemplates[pathUsed];
			} else {
				std::istream *fp = LocalizationUtils::OpenStream(context, filename, pathUsed);
				if (fp) {
					std::istream &reader = *fp;
					{
						MethodTimer(HTMLTemplateRenderer.RenderAll, filename, context);
						TemplateParser *tp = GetParser();
						rendererConfig = tp->Parse(reader, filename, 1L, rendererConfig.GetAllocator(), roaParserConfig);
						delete tp;
						theRendererConfig = rendererConfig;
					}
					delete fp;
				} else {
					String logMsg("HTMLTemplateRenderer::RenderAll: cannot open file ");
					logMsg << filename << ".html";
					SystemLog::Error(logMsg);
				}
			}
		}
	} else {
		// look for /Template
		MethodTimer(HTMLTemplateRenderer.RenderAll, "Template", context);
		ROAnything templ;
		if (args.IsDefined("Template")) {
			templ = args["Template"];
		} else {
			// bail out.
			OStringStream str;
			str << "HTMLTemplateRenderer::RenderAll: neither Template nor TemplateName is defined :";
			args.PrintOn(str); // log what we've got
			SystemLog::Error(str.str());
			return;
		}

		String buf;
		for (long i = 0, size = templ.GetSize(); i < size; ++i) {
			// PS: only append anonymous entries to allow for future parameters
			// PS: this will take care of things like /Options /Method in subclass FormRenderer
			if ( 0 == templ.SlotName(i) ) {
				buf.Append(templ[i].AsCharPtr());
			}
		}
		IStringStream reader(buf);
		TemplateParser *tp = GetParser();
		rendererConfig = tp->Parse(reader, "from config", 1L, rendererConfig.GetAllocator(), roaParserConfig);
		delete tp;
		theRendererConfig = rendererConfig;

	}
	Render(reply, context, theRendererConfig);
}
// エントリポイント
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE, LPTSTR, int )
{
	LARGE_INTEGER			nNowTime, nLastTime;		// 現在とひとつ前の時刻
	LARGE_INTEGER			nTimeFreq;					// 時間単位

    // 画面サイズ
    g_nClientWidth  = VIEW_WIDTH;						// 幅
    g_nClientHeight = VIEW_HEIGHT;						// 高さ

	// Register the window class
    WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
                      _T( "D3D Sample" ), NULL };
    RegisterClassEx( &wc );

	RECT rcRect;
	SetRect( &rcRect, 0, 0, g_nClientWidth, g_nClientHeight );
	AdjustWindowRect( &rcRect, WS_OVERLAPPEDWINDOW, FALSE );
    g_hWnd = CreateWindow( _T( "D3D Sample" ), _T( "3DCheckHit_3_2" ),
						   WS_OVERLAPPEDWINDOW, 100, 20, rcRect.right - rcRect.left, rcRect.bottom - rcRect.top,
						   GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D() ) && SUCCEEDED( MakeShaders() ) )
    {
        // Create the shaders
        if( SUCCEEDED( InitDrawModes() ) )
        {
			if ( SUCCEEDED( InitGeometry() ) ) {					// ジオメトリ作成
				
				InitPlayer();										// プレイヤーの初期化
				// Show the window
				ShowWindow( g_hWnd, SW_SHOWDEFAULT );
				UpdateWindow( g_hWnd );
				
				QueryPerformanceFrequency( &nTimeFreq );			// 時間単位
				QueryPerformanceCounter( &nLastTime );				// 1フレーム前時刻初期化

				// Enter the message loop
				MSG msg;
				ZeroMemory( &msg, sizeof( msg ) );
				while( msg.message != WM_QUIT )
				{
					MovePlayer();
					Render();
					do {
						if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
						{
							TranslateMessage( &msg );
							DispatchMessage( &msg );
						}
						QueryPerformanceCounter( &nNowTime );
					} while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 90 ) ) &&
							 ( msg.message != WM_QUIT ) );
					while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 60 ) ) &&
						   ( msg.message != WM_QUIT ) )
					{
						QueryPerformanceCounter( &nNowTime );
					}
					nLastTime = nNowTime;
					g_pSwapChain->Present( 0, 0 );					// 表示
				}
			}
        }
    }

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( _T( "D3D Sample" ), wc.hInstance );
    return 0;
}
Beispiel #23
0
	void GameManager::GameTick()
	{
		Update();
		Render();
	}
Beispiel #24
0
 // Renders one copy of the prepared geometry, given a model-view-projection matrix.
 inline void Render(glm::mat4 *mvpMat) {
     Render(NULL, mvpMat);
 }
Beispiel #25
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ) // 프로그램 진입점
{
	WNDCLASSEX wc =                                                           // 윈도우 클래스 정의,등록
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		"ProG", NULL
	};
	RegisterClassEx( &wc );

	HWND hWnd = CreateWindow( "ProG", "ProG",  // 윈도우 생성
		WS_BORDER | WS_SYSMENU, 0, 0, 1680, 1030,     ////   좌표 변수 처리
		NULL, NULL, wc.hInstance, NULL );

	CDevice::GetInstance()->Init(hWnd, 1680, 1030);

	if( SUCCEEDED( InitD3D( hWnd ) ) ) // Direct3D초기화
	{
		ShowWindow( hWnd, SW_SHOWDEFAULT ); // 윈도우 출력
		UpdateWindow( hWnd );

		MSG msg;
		while(true) // 메시지 루프
		{
			if(PeekMessage(&msg, NULL,NULL, NULL, PM_REMOVE))
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			else
			{
				first_time = GetTickCount();
				if(g_Load.Logo_Start == true)
				{
					Loading();
					if(g_Load.Out_Exit() == true)
					{
						PostQuitMessage( 0 );
					}

				}
				if(g_Load.Logo_Start == false)
				{
				Update(); 
				Destroy();
				Active();
				Collision();
				Create();
				Stage1();
				EL();
				World_Time = World_Time + tick;
				
				}
				Render();
				tick = (float)(GetTickCount() - first_time)/(float)1000;
			}
			if(msg.message == WM_QUIT)
			{
				break;
			}

		}
	}

	Cleanup();

	UnregisterClass( "ProG", wc.hInstance );  // 등록된 클래스 소거

	return 0;
}
Beispiel #26
0
 // Convenience method to render a single copy of a geometry.
 inline void RenderSimpleGeom(glm::mat4* mvpMat, SimpleGeom *sg) {
     BeginRender(sg->vbuf);
     Render(sg->ibuf, mvpMat);
     EndRender();
 }
Beispiel #27
0
void CMenus::OnRender()
{
	/*
	// text rendering test stuff
	render_background();

	CTextCursor cursor;
	TextRender()->SetCursor(&cursor, 10, 10, 20, TEXTFLAG_RENDER);
	TextRender()->TextEx(&cursor, "ようこそ - ガイド", -1);

	TextRender()->SetCursor(&cursor, 10, 30, 15, TEXTFLAG_RENDER);
	TextRender()->TextEx(&cursor, "ようこそ - ガイド", -1);
	
	//Graphics()->TextureSet(-1);
	Graphics()->QuadsBegin();
	Graphics()->QuadsDrawTL(60, 60, 5000, 5000);
	Graphics()->QuadsEnd();
	return;*/
	
	if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
		SetActive(true);

	if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
	{
		CUIRect Screen = *UI()->Screen();
		Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
		RenderDemoPlayer(Screen);
	}
	
	if(Client()->State() == IClient::STATE_ONLINE && m_pClient->m_ServerMode == m_pClient->SERVERMODE_PUREMOD)
	{
		Client()->Disconnect();
		SetActive(true);
		m_Popup = POPUP_PURE;
	}
	
	if(!IsActive())
	{
		m_EscapePressed = false;
		m_EnterPressed = false;
		m_NumInputEvents = 0;
		return;
	}
	
	// update colors
	vec3 Rgb = HslToRgb(vec3(g_Config.m_UiColorHue/255.0f, g_Config.m_UiColorSat/255.0f, g_Config.m_UiColorLht/255.0f));
	ms_GuiColor = vec4(Rgb.r, Rgb.g, Rgb.b, g_Config.m_UiColorAlpha/255.0f);

	ms_ColorTabbarInactiveOutgame = vec4(0,0,0,0.25f);
	ms_ColorTabbarActiveOutgame = vec4(0,0,0,0.5f);

	float ColorIngameScaleI = 0.5f;
	float ColorIngameAcaleA = 0.2f;
	ms_ColorTabbarInactiveIngame = vec4(
		ms_GuiColor.r*ColorIngameScaleI,
		ms_GuiColor.g*ColorIngameScaleI,
		ms_GuiColor.b*ColorIngameScaleI,
		ms_GuiColor.a*0.8f);
	
	ms_ColorTabbarActiveIngame = vec4(
		ms_GuiColor.r*ColorIngameAcaleA,
		ms_GuiColor.g*ColorIngameAcaleA,
		ms_GuiColor.b*ColorIngameAcaleA,
		ms_GuiColor.a);
    
	// update the ui
	CUIRect *pScreen = UI()->Screen();
	float mx = (m_MousePos.x/(float)Graphics()->ScreenWidth())*pScreen->w;
	float my = (m_MousePos.y/(float)Graphics()->ScreenHeight())*pScreen->h;
		
	int Buttons = 0;
	if(m_UseMouseButtons)
	{
		if(Input()->KeyPressed(KEY_MOUSE_1)) Buttons |= 1;
		if(Input()->KeyPressed(KEY_MOUSE_2)) Buttons |= 2;
		if(Input()->KeyPressed(KEY_MOUSE_3)) Buttons |= 4;
	}
		
	UI()->Update(mx,my,mx*3.0f,my*3.0f,Buttons);
    
	// render
	if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
		Render();

	// render cursor
	Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CURSOR].m_Id);
	Graphics()->QuadsBegin();
	Graphics()->SetColor(1,1,1,1);
	IGraphics::CQuadItem QuadItem(mx, my, 24, 24);
	Graphics()->QuadsDrawTL(&QuadItem, 1);
	Graphics()->QuadsEnd();

	// render debug information
	if(g_Config.m_Debug)
	{
		CUIRect Screen = *UI()->Screen();
		Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);

		char aBuf[512];
		str_format(aBuf, sizeof(aBuf), "%p %p %p", UI()->HotItem(), UI()->ActiveItem(), UI()->LastActiveItem());
		CTextCursor Cursor;
		TextRender()->SetCursor(&Cursor, 10, 10, 10, TEXTFLAG_RENDER);
		TextRender()->TextEx(&Cursor, aBuf, -1);
	}

	m_EscapePressed = false;
	m_EnterPressed = false;
	m_NumInputEvents = 0;
}
Beispiel #28
0
void
LayerManagerComposite::EndTransaction(DrawThebesLayerCallback aCallback,
                                      void* aCallbackData,
                                      EndTransactionFlags aFlags)
{
  NS_ASSERTION(mInTransaction, "Didn't call BeginTransaction?");
  NS_ASSERTION(!aCallback && !aCallbackData, "Not expecting callbacks here");
  mInTransaction = false;

  if (!mIsCompositorReady) {
    return;
  }
  mIsCompositorReady = false;

#ifdef MOZ_LAYERS_HAVE_LOG
  MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
  Log();
#endif

  if (mDestroyed) {
    NS_WARNING("Call on destroyed layer manager");
    return;
  }

  if (mRoot && mClonedLayerTreeProperties) {
    MOZ_ASSERT(!mTarget);
    nsIntRegion invalid =
      mClonedLayerTreeProperties->ComputeDifferences(mRoot, nullptr, &mGeometryChanged);
    mClonedLayerTreeProperties = nullptr;

    mInvalidRegion.Or(mInvalidRegion, invalid);
  } else if (!mTarget) {
    mInvalidRegion.Or(mInvalidRegion, mRenderBounds);
  }

  if (mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) {
    if (aFlags & END_NO_COMPOSITE) {
      // Apply pending tree updates before recomputing effective
      // properties.
      mRoot->ApplyPendingUpdatesToSubtree();
    }

    // The results of our drawing always go directly into a pixel buffer,
    // so we don't need to pass any global transform here.
    mRoot->ComputeEffectiveTransforms(gfx::Matrix4x4());

    Render();
    mGeometryChanged = false;
  } else {
    // Modified layer tree
    mGeometryChanged = true;
  }

  mCompositor->ClearTargetContext();
  mTarget = nullptr;

#ifdef MOZ_LAYERS_HAVE_LOG
  Log();
  MOZ_LAYERS_LOG(("]----- EndTransaction"));
#endif
}
Beispiel #29
0
void Engine::Render() {
    Render(renderList);
}
Beispiel #30
0
void TileMap::Render( int OffsetX, int OffsetY )
{
	Render( OffsetX, OffsetY, 1.0f, 1.0f );
}