Esempio n. 1
0
void surface_set_target(int id)
{
  draw_batch_flush(batch_flush_deferred);

  get_surface(surface,id);
  d3ddev->SetRenderTarget(0, surface.surf);

  d3d_set_projection_ortho(0, 0, surface.width, surface.height, 0);
}
Esempio n. 2
0
void screen_init()
{
	enigma::gui_width = window_get_region_width_scaled();
	enigma::gui_height = window_get_region_height_scaled();
	
	d3dmgr->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	d3dmgr->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	
    if (!view_enabled)
    {
      d3dmgr->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

      screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
      d3d_set_projection_ortho(0, 0, room_width, room_height, 0);
    } else {
      for (view_current = 0; view_current < 7; view_current++)
      {
        if (view_visible[(int)view_current])
        {
          int vc = (int)view_current;

          screen_set_viewport(view_xport[vc], view_yport[vc],
            (window_get_region_width_scaled() - view_xport[vc]), (window_get_region_height_scaled() - view_yport[vc]));
          d3d_set_projection_ortho(view_xview[vc], view_wview[vc] + view_xview[vc], view_yview[vc], view_hview[vc] + view_yview[vc], view_angle[vc]);
          break;
        }
      }
    }

	d3dmgr->SetRenderState(D3DRS_LIGHTING, FALSE);
	d3dmgr->SetRenderState(D3DRS_ZENABLE, TRUE);
	d3dmgr->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	d3dmgr->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001);
	d3dmgr->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); 
	d3dmgr->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
	d3dmgr->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	d3dmgr->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	draw_set_color(c_white);
}
Esempio n. 3
0
void surface_set_target(int id)
{
  get_surface(surf,id);
  texture_reset();
  //This fixes several consecutive surface_set_target() calls without surface_reset_target.
  if (enigma::bound_framebuffer != 0) glPopAttrib(); glPopMatrix();
  enigma::bound_framebuffer = surf->fbo;
  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, surf->fbo); //bind it
  glPushMatrix(); //So you can pop it in the reset
  glPushAttrib(GL_VIEWPORT_BIT); //same
  screen_set_viewport(0, 0, surf->width, surf->height);
  d3d_set_projection_ortho(0, 0, surf->width, surf->height, 0);
}
Esempio n. 4
0
void screen_init()
{
  enigma::gui_width = window_get_region_width_scaled();
  enigma::gui_height = window_get_region_height_scaled();

  glClearColor(0,0,0,0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if (!view_enabled)
  {
    glClearColor(0,0,0,0);
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
	d3d_set_projection_ortho(0, 0, room_width, room_height, 0);
  } else {
    for (view_current = 0; view_current < 7; view_current++)
    {
      if (view_visible[(int)view_current])
      {
        int vc = (int)view_current;

          glClearColor(0,0,0,0);

          screen_set_viewport(view_xport[vc], view_yport[vc], view_wport[vc], view_hport[vc]);
		  d3d_set_projection_ortho(view_xview[vc], view_yview[vc], view_wview[vc], view_hview[vc], 0);
        break;
      }
    }
  }

  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glEnable(GL_ALPHA_TEST);
  glEnable(GL_TEXTURE_2D);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glAlphaFunc(GL_ALWAYS,0);
  texture_reset();
  draw_set_color(c_white);
}
Esempio n. 5
0
void surface_copy(int destination, float x, float y, int source)
{
    get_surface(ssurf,source);
    get_surface(dsurf,destination);
    unsigned char *surfbuf=new unsigned char[dsurf->width*dsurf->height*4];
    glBindFramebuffer(GL_READ_FRAMEBUFFER, ssurf->fbo);
	glReadPixels(0,0,dsurf->width,dsurf->height,GL_RGBA,GL_UNSIGNED_BYTE,surfbuf);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dsurf->fbo);
    glPushMatrix();
    glPushAttrib(GL_VIEWPORT_BIT);
    screen_set_viewport(0, 0, dsurf->width, dsurf->height);
    d3d_set_projection_ortho(0, 0, dsurf->width, dsurf->height, 0);
	glRasterPos2d(x, y);
	glDrawPixels(dsurf->width,dsurf->height,GL_RGBA,GL_UNSIGNED_BYTE,surfbuf);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::bound_framebuffer);
    glPopAttrib();
    glPopMatrix();
	glRasterPos2d(0, 0);
	delete[] surfbuf;
}
Esempio n. 6
0
void screen_redraw()
{
  //d3dmgr->EndShapesBatching(); //If called inside bound surface we need to finish drawing
  d3dmgr->BeginScene();
  // Clean up any textures that ENIGMA may still think are binded but actually are not
  d3d_set_zwriteenable(true);
  if (!view_enabled)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    
    clear_view(0, 0, room_width, room_height, 0, background_showcolor);
    draw_back();
    draw_insts();
    draw_tiles();
  }
  else
  {
    //TODO: Possibly implement view option from Stupido to control which view clears the background
    // Only clear the background on the first visible view by checking if it hasn't been cleared yet
    bool draw_backs = true;
    bool background_allviews = true; // FIXME: Create a setting for this.
    for (view_current = 0; view_current < 8; view_current++)
    {
      int vc = (int)view_current;
      if (!view_visible[vc])
        continue;
      
      int vob = (int)view_object[vc];
      if (vob != -1)
        follow_object(vob, vc);

      screen_set_viewport(view_xport[vc], view_yport[vc], view_wport[vc], view_hport[vc]);
	  
      clear_view(view_xview[vc], view_yview[vc], view_wview[vc], view_hview[vc], view_angle[vc], background_showcolor && draw_backs);

      if (draw_backs)
        draw_back();
      
      draw_insts();
      
      if (draw_tiles())
        break;
      draw_backs = background_allviews;
    }
    view_current = 0;
  }

  // Now process the sub event of draw called draw gui
  // It is for drawing GUI elements without view scaling and transformation
  if (enigma::gui_used)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    d3d_set_projection_ortho(0, 0, enigma::gui_width, enigma::gui_height, 0);
	
    // Clear the depth buffer if hidden surface removal is on at the beginning of the draw step.
    if (enigma::d3dMode)
      d3dmgr->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    draw_gui();
  }

  d3dmgr->EndScene();

  ///TODO: screen_refresh() shouldn't be in screen_redraw(). They are separate functions for a reason.
  screen_refresh();
}
Esempio n. 7
0
void screen_redraw()
{
  // Clean up any textures that ENIGMA may still think are binded but actually are not
  d3d_set_zwriteenable(true);
  if (!view_enabled)
  {
    if (bound_framebuffer != 0) //This fixes off-by-one error when rendering on surfaces. This should be checked to see if other GPU's have the same effect
      screen_set_viewport(1, 1, window_get_region_width_scaled(), window_get_region_height_scaled());
    else
      screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    
    clear_view(0, 0, room_width, room_height, background_showcolor);
    draw_back();
    draw_insts();
    draw_tiles();
  }
  else
  {
    //TODO: Possibly implement view option from Stupido to control which view clears the background
    // Only clear the background on the first visible view by checking if it hasn't been cleared yet
    bool draw_backs = true;
    bool background_allviews = true; // FIXME: Create a setting for this.
    for (view_current = 0; view_current < 8; view_current++)
    {
      int vc = (int)view_current;
      if (!view_visible[vc])
        continue;
      
      int vob = (int)view_object[vc];
      if (vob != -1)
        follow_object(vob, vc);

      if (bound_framebuffer != 0) //This fixes off-by-one error when rendering on surfaces. This should be checked to see if other GPU's have the same effect
        screen_set_viewport(view_xport[vc]+1, view_yport[vc]+1, view_wport[vc], view_hport[vc]);
      else
        printf("%d %d %d %d\n", (int)view_xport[vc], (int)view_yport[vc], (int)view_wport[vc], (int)view_hport[vc]),
        screen_set_viewport(view_xport[vc], view_yport[vc], view_wport[vc], view_hport[vc]);
	  
      clear_view(view_xview[vc], view_yview[vc], view_wview[vc], view_hview[vc], background_showcolor && draw_backs);

      if (draw_backs)
        draw_back();
      
      draw_insts();
      
      if (draw_tiles())
        break;
      draw_backs = background_allviews;
    }
    view_current = 0;
  }

  // Now process the sub event of draw called draw gui
  // It is for drawing GUI elements without view scaling and transformation
  if (enigma::gui_used)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
	d3d_set_projection_ortho(0, 0, enigma::gui_width, enigma::gui_height, 0);
	
    // Clear the depth buffer if hidden surface removal is on at the beginning of the draw step.
    if (enigma::d3dMode)
      glClear(GL_DEPTH_BUFFER_BIT);

    draw_gui();
  }

  if (enigma::msaa_fbo != 0) {
    GLint fbo;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fbo);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::msaa_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    //TODO: Change the code below to fix this to size properly to views
    glBlitFramebuffer(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled(), 0, 0, window_get_region_width_scaled(), window_get_region_height_scaled(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
    // glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
  }

  ///TODO: screen_refresh() shouldn't be in screen_redraw(). They are separate functions for a reason.
  if (bound_framebuffer==0 || enigma::msaa_fbo != 0) { screen_refresh(); }
}