Esempio n. 1
0
File: gui.c Progetto: dmdware/vec
void Ortho(int width, int height, float r, float g, float b, float a)
{
	Shader* s;
	CHECKGLERROR();
	UseS(SH_ORTHO);
	s = g_sh+g_curS;
	glUniform1f(s->slot[SSLOT_WIDTH], (float)width);
	glUniform1f(s->slot[SSLOT_HEIGHT], (float)height);
	glUniform4f(s->slot[SSLOT_COLOR], r, g, b, a);
	g_currw = width;
	g_currh = height;
	CHECKGLERROR();
}
Esempio n. 2
0
File: gui.c Progetto: dmdware/vec
void GUI_draw2(GUI *gui)
{
	unsigned int spi;
	Sprite* sp;
	Widget *bw;

	glClear(GL_DEPTH_BUFFER_BIT);
	glDisable(GL_DEPTH_TEST);
	CHECKGLERROR();
	Ortho(g_width, g_height, 1, 1, 1, 1);
	CHECKGLERROR();

	/* TODO
	in Widget::
	Widget_draw((Widget*)gui);
	CHECKGLERROR();
	Widget_drawover((Widget*)gui);
	*/

	if(g_appmode == APPMODE_PLAY &&
		g_keys[SDL_SCANCODE_TAB])
	{
//		Lobby_DrawPyL();
//		Lobby_DrawState();
	}

	spi = g_cursor[g_curst];
	sp = &g_sp[spi];

	bw = (Widget*)gui;

	bw->crop[0] = 0;
	bw->crop[1] = 0;
	bw->crop[2] = (float)g_width-1;
	bw->crop[3] = (float)g_height-1;

	DrawImage(g_tex[sp->difftexi].texname, 
		g_mouse.x+sp->offset[0], g_mouse.y+sp->offset[1], 
		g_mouse.x+sp->offset[2], g_mouse.y+sp->offset[3], 
		0,0,1,1, bw->crop);
	
	CHECKGLERROR();

	EndS();
	CHECKGLERROR();

	glEnable(GL_DEPTH_TEST);
}
Esempio n. 3
0
Texture2d::Texture2d(bool multisampled, int numSamples) : m_multiSampled(multisampled), m_numSamples(numSamples)
{
    if(m_multiSampled)
    {
        m_target = GL_TEXTURE_2D_MULTISAMPLE;
    }
    else
        m_target = GL_TEXTURE_2D;


    glGenTextures(1, &m_id);
    glBindTexture(m_target, m_id);

    // multisampled textures only support nearest neighbour lookup
    if( !m_multiSampled )
    {
        //glTexParameteri( m_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
        glTexParameteri( m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
        // when texture area is large, bilinear filter the original
        //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
        glTexParameteri( m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
        //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

        // the texture wraps over at the edges (repeat)
        glTexParameterf( m_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( m_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    }

    CHECKGLERROR();


}
Esempio n. 4
0
void SkyBox::render(const TCamera& camera)
{
  assert( m_bInitialized );  
  
  if (m_cubemaps.empty())
  {
    fprintf(stderr, "ERROR : no cubemap specified\n");
    exit(0);
  }
  
  
  glDisable( GL_DEPTH_TEST );
  glDepthMask( GL_FALSE );  
  glDisable( GL_CULL_FACE );  
  
  glEnable( GL_TEXTURE_CUBE_MAP_SEAMLESS );  
  
  m_Program->bind();
  {    
    //-------------------------------------------------
    if (m_bAutoRotation)
    {
      m_spin = fmodf( m_spin+0.1f, 360.0f);
      glm::vec3 axis = glm::vec3( 1.0f, 0.7f, -0.5f );
      
      m_rotateMatrix = glm::rotate( glm::mat4(1.0f), m_spin, axis);
      m_invRotateMatrix = glm::mat3( glm::rotate( glm::mat4(1.0f), -m_spin, axis) );
    }
    //-------------------------------------------------
    
    // Vertex uniform
    glm::mat4 followCamera = glm::translate( glm::mat4(1.0f), camera.getPosition());
    glm::mat4 model = m_CubeMesh->getModelMatrix() * followCamera * m_rotateMatrix;
    glm::mat4 mvp = camera.getViewProjMatrix() * model;    
    m_Program->setUniform( "uModelViewProjMatrix", mvp);
    
    // Fragment uniform
    m_Program->setUniform( "uCubemap", 0);
    
    m_cubemaps[m_curIdx]->bind( 0u );
      m_CubeMesh->draw();    
    m_cubemaps[m_curIdx]->unbind( 0u );
  }
  m_Program->unbind();
  
  glDisable( GL_TEXTURE_CUBE_MAP_SEAMLESS );
     
  //glEnable( GL_CULL_FACE );
  glDepthMask( GL_TRUE );
  glEnable( GL_DEPTH_TEST ); 
  
  CHECKGLERROR();
}
Esempio n. 5
0
Texture3dPtr Texture3d::create( int textureFormat, int xres, int yres, int zres )
{
    Texture3dPtr result = Texture3dPtr(new Texture3d());

    result->m_xres = xres;
    result->m_yres = yres;
    result->m_zres = zres;
    result->m_textureFormat = textureFormat;

    glBindTexture(GL_TEXTURE_3D, result->m_id);
    glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 );
    glTexImage3D( GL_TEXTURE_3D, 0, result->m_textureFormat, result->m_xres, result->m_yres, result->m_zres, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    CHECKGLERROR();

    return result;
}
Esempio n. 6
0
Texture2dPtr Texture2d::create( int textureFormat, int xres, int yres, bool multisampled, int numSamples )
{
    Texture2dPtr result = Texture2dPtr(new Texture2d(multisampled, numSamples));

    result->m_xres = xres;
    result->m_yres = yres;
    result->m_textureFormat = textureFormat;
    glBindTexture(result->m_target, result->m_id);

    if( !multisampled )
        glTexImage2D(GL_TEXTURE_2D, 0, result->m_textureFormat, result->m_xres, result->m_yres, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    else
        glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, numSamples, result->m_textureFormat, result->m_xres, result->m_yres, true );

    if( CHECKGLERROR() )
    {

        std::cout << "Texture2d::create: unable to allocate gpu memory for texture\n";
        return Texture2dPtr();
        //TODO: investigate exception handling + qt throw std::runtime_error(glErrorString(error).c_str());
    }

    return result;
}