Jump to content

  • Log In with Google      Sign In   
  • Create Account


GorbGorb

Member Since 25 Jun 2011
Offline Last Active Sep 20 2012 04:39 AM

Topics I've Started

Problem with gles 2 textures

30 August 2012 - 03:39 AM

Hi, I'm learning gles 2 android ndk at the moment, but I can't display a texture. I expect my code to render a black texture on the screen, but all I get is some color garbage. This is my rendering routine:
[source lang="cpp"] gl_context::create_context( s ); glViewport( 0 , 0 , gl_context::width() , gl_context::height() ); glClearColor( 0.0f , 0.0f , 0.0f , 0.0f ); GLuint shader_program = 0; GLuint position = 0; GLuint texture_coord = 1; GLuint sampler = 0; const char* vertex_shader_source = "attribute vec4 position; \n" "attribute vec2 a_texture_coord; \n" "varying vec2 v_texture_coord; \n" "void main() \n" "{ \n" " gl_Position = position; \n" " v_texture_coord = a_texture_coord; \n" "} \n"; const char* fragment_shader_source = "precision mediump float; \n" "uniform sampler2D sampler; \n" "varying vec2 v_texture_coord; \n" "void main() \n" "{ \n" " gl_FragColor = texture2D( sampler , v_texture_coord );" //" gl_FragColor = vec4( 1.0 , 0.0 , 0.0 , 1.0 );" //uncommenting this results in a red screen, so I guess I have a valid gles 2 context "} \n"; GLuint vertex_shader = glCreateShader( GL_VERTEX_SHADER ); glShaderSource( vertex_shader , 1 , &vertex_shader_source , 0 ); glCompileShader( vertex_shader ); GLuint fragment_shader = glCreateShader( GL_FRAGMENT_SHADER ); glShaderSource( fragment_shader , 1 , &fragment_shader_source , 0 ); glCompileShader( fragment_shader ); shader_program = glCreateProgram(); glAttachShader( shader_program , vertex_shader ); glAttachShader( shader_program , fragment_shader ); glBindAttribLocation( shader_program , position , "position" ); glBindAttribLocation( shader_program , texture_coord , "a_texture_coord" ); glLinkProgram( shader_program ); glUseProgram( shader_program ); sampler = glGetUniformLocation( shader_program , "sampler" ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D , 0 ) ; std::vector< GLubyte > buffer( 64 * 64 * 3 , 0 ); glTexImage2D( GL_TEXTURE_2D , 0 , GL_RGB , 64 , 64 , 0 , GL_RGB , GL_UNSIGNED_BYTE , buffer.data() ); glUniform1i( sampler , 0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); const GLfloat vertex_positions[] = { -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, }; const GLfloat texture_coords[] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, }; glVertexAttribPointer( position , 2 , GL_FLOAT , GL_FALSE , 0 , vertex_positions ); glEnableVertexAttribArray( position ); glVertexAttribPointer( texture_coord , 2 , GL_FLOAT , GL_FALSE , 0 , texture_coords ); glEnableVertexAttribArray( texture_coord ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); glDisableVertexAttribArray( position ); glDisableVertexAttribArray( texture_coord ); gl_context::swap_buffers();[/source]

entities: construction, storage and destruction

09 February 2012 - 01:38 PM

Hi, I'm not sure how to implement an entity system, as described in http://t-machine.org...opment-part-1/. Especially construction, communication between components and managing entity lifetime is giving me a hard time. Here are a few alternatives I thought about:

1) Store indexes to components in the entity object
a) in an std::map (or a sorted vector). Since map lookup is slow, I have to store additional references in components that need to access other components very often (for example, the physics component needs fast access to the transform component).
memory overhead per component:
- in map: 1 int component id , 1 int/ptr for access to specific component
- in component: optional fast-access references, optional ptr to entity object
b) in an array that is large enough to hold an index for each component type in my entity system. Finding a specific component of an entity is just indexing an array, but entities with few components suffer from a heavy memory overhead. In addition, I get cache misses if I access that lookup table very often.
memory overhead per component:
- in lookup table: 1 int component id , even for nonexistent components
- in component: 1 ptr to component entity object
2) Destroy references to components after construction and keep a reference count in the entity object
After construction, each component stores references to other components itself. Afterwards, the reference table or map is destroyed. When processing a component, I have to check wether the entity is still valid or deleted.
memory overhead per component:
- 1 ptr to reference count
- references to all possibly needed components, cannot query a component past construction

Currently, I tend towards 1a). I like that it's possible to add or remove components from entities during their entire lifetime, and it probably scales better if I want to add many different components. What are your thoughts?

template specialization problem

13 July 2011 - 03:43 PM

Hello,

I've a problem with a specialization of template member of a template class. Here is what I want to do:


template<class X>
class A
{
	template<class Y>
	void func();
	template<>
	void func<X>();
};


This code compiles (and works) with Visual C++, but according to the standard, it's wrong: If a template member of a template class is specialized, it has to be done in the namespace the class was defined. I tried to work around that, but I can't figure out how:
I tried
template<class X>
class A
{
	template<class Y>
	void func();
};
template<> template<class Y>
void A<Y>::func<Y>();
and
template<class X>
class A
 {
 	template<class Y>
 	void func();
 };
template<class X> template<>
void A<X>::func<X>();
, but both versions don't work.

Does anybody have a solution for what I want to achieve?

PARTNERS