Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualVorel512

Posted 12 April 2012 - 06:27 AM

Here is my rendering code:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
	glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	Sprites *fgh;
	Attribute_holder *asd;

	for (unsigned int i=0; [gManager getAttributeArrayCount]>i; i++)
	{
		asd = [gManager getAttributeAtIndex:i];
		if ([asd getShow] == 1)
		{
			fgh = [gManager getSpriteAtIndex:[asd getSpriteID]];		  
			glBindVertexArrayOES([fgh getVertexArray]);
		  
			glUseProgram(_program);
			[asd.effect prepareToDraw];
		  
			glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
		  
			//for debugging
			//glDrawArrays(GL_LINE_LOOP, 0, 6);
		}
	}
}
I am storing the positions, isdisplayable , etc variables in Attribute_holder, and the vertexes and other stuff like textures in Sprites. gManager is my NSMutableArray where I store them like:
attrib0 - sprite0
attrib1 - sprite0
attrib2 - sprite1

I load the vertexes/uvs/normals to a main buffer and the textures to a "child" buffer:
- (void) createBuffers:(unsigned short) num
{
	IndicesArray[0] = 0;
	IndicesArray[1] = 1;
	IndicesArray[2] = 2;
	IndicesArray[3] = 3;

	glGenVertexArraysOES(num, &_vertexArray);
	glBindVertexArrayOES(_vertexArray);

	glGenBuffers(num, &_vertexBuffer);
	glGenBuffers(num, &_indexBuffer);

	glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);

	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndicesArray), IndicesArray, GL_STATIC_DRAW);
	glBufferData(GL_ARRAY_BUFFER, sizeof(VectorArray), VectorArray, GL_STATIC_DRAW);

	glEnableVertexAttribArray(GLKVertexAttribPosition);
	glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0));

	glEnableVertexAttribArray(GLKVertexAttribNormal);
	glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12));

	glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
	glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24));

	glBindVertexArrayOES(0);

	And after the buffering I bind the texture name to the attrib array.
	tempAttrib.effect.texture2d0.name = [tempSprite [getChildTexture:0];
}

And here is the object for the textures:
- (void) setTexture:(NSString*)fileName ofType:(NSString*)type
{  
	NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];

	NSError *error;

	NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
														GLKTextureLoaderOriginBottomLeft,nil];

	texture = [GLKTextureLoader textureWithContentsOfFile:path
													   options:options error:&error];

	if (texture == nil)
		NSLog(@"Error loading texture: %@", [error localizedDescription]);

	glBindTexture( GL_TEXTURE_2D, texture.name );

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

	tex = [[GLKEffectPropertyTexture alloc] init];
	tex.enabled = YES;
	tex.envMode = GLKTextureEnvModeDecal;
	tex.name = texture.name;

	//glActiveTexture(GL_TEXTURE0);
	//glBindTexture(GL_TEXTURE_2D, 0);
}

The weird thing is that if I remove the texparams and stuff the textures rendered correctly.

#3Vorel512

Posted 12 April 2012 - 06:25 AM

Here is my rendering code:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    Sprites *fgh;
    Attribute_holder *asd;

    for (unsigned int i=0; [gManager getAttributeArrayCount]>i; i++)
    {
	    asd = [gManager getAttributeAtIndex:i];
	    if ([asd getShow] == 1)
	    {
		    fgh = [gManager getSpriteAtIndex:[asd getSpriteID]];		   
		    glBindVertexArrayOES([fgh getVertexArray]);
		   
		    glUseProgram(_program);
		    [asd.effect prepareToDraw];
		   
		    glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
		   
		    //for debugging
		    //glDrawArrays(GL_LINE_LOOP, 0, 6);
	    }
    }
}
I am storing the positions, isdisplayable , etc variables in Attribute_holder, and the vertexes and other stuff like textures in Sprites. gManager is my NSMutableArray where I store them like:
attrib0 - sprite0
attrib1 - sprite0
attrib2 - sprite1

I load the vertexes/uvs/normals to a main buffer and the textures to a "child" buffer:
- (void) createBuffers:(unsigned short) num
{
    IndicesArray[0] = 0;
    IndicesArray[1] = 1;
    IndicesArray[2] = 2;
    IndicesArray[3] = 3;

    glGenVertexArraysOES(num, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);

    glGenBuffers(num, &_vertexBuffer);
    glGenBuffers(num, &_indexBuffer);

    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);

    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndicesArray), IndicesArray, GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(VectorArray), VectorArray, GL_STATIC_DRAW);

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0));

    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12));

    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24));

    glBindVertexArrayOES(0);

    And after the buffering I bind the texture name to the attrib array.
    tempAttrib.effect.texture2d0.name = [tempSprite [getChildTexture:0];
}

And here is the object for the textures:
- (void) setTexture:(NSString*)fileName ofType:(NSString*)type
{   
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];

    NSError *error;

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
													    GLKTextureLoaderOriginBottomLeft,nil];

    texture = [GLKTextureLoader textureWithContentsOfFile:path
													   options:options error:&error];

    if (texture == nil)
	    NSLog(@"Error loading texture: %@", [error localizedDescription]);

    glBindTexture( GL_TEXTURE_2D, texture.name );

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

    tex = [[GLKEffectPropertyTexture alloc] init];
    tex.enabled = YES;
    tex.envMode = GLKTextureEnvModeDecal;
    tex.name = texture.name;

    //glActiveTexture(GL_TEXTURE0);
    //glBindTexture(GL_TEXTURE_2D, 0);
}

#2Vorel512

Posted 12 April 2012 - 06:25 AM

Here is my rendering code:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    Sprites *fgh;
    Attribute_holder *asd;

    for (unsigned int i=0; [gManager getAttributeArrayCount]>i; i++)
    {
	    asd = [gManager getAttributeAtIndex:i];
	    if ([asd getShow] == 1)
	    {
		    fgh = [gManager getSpriteAtIndex:[asd getSpriteID]];		   
		    glBindVertexArrayOES([fgh getVertexArray]);
		   
		    glUseProgram(_program);
		    [asd.effect prepareToDraw];
		   
		    glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
		   
		    //for debugging
		    //glDrawArrays(GL_LINE_LOOP, 0, 6);
	    }
    }
}
I am storing the positions, isdisplayable , etc variables in Attribute_holder, and the vertexes and other stuff like textures in Sprites. gManager is my NSMutableArray where I store them like:
attrib0 - sprite0
attrib1 - sprite0
attrib2 - sprite1

I load the vertexes/uvs/normals to a main buffer and the textures to a "child" buffer:
- (void) createBuffers:(unsigned short) num
{
    IndicesArray[0] = 0;
    IndicesArray[1] = 1;
    IndicesArray[2] = 2;
    IndicesArray[3] = 3;

    glGenVertexArraysOES(num, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);

    glGenBuffers(num, &_vertexBuffer);
    glGenBuffers(num, &_indexBuffer);

    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);

    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndicesArray), IndicesArray, GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(VectorArray), VectorArray, GL_STATIC_DRAW);

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0));

    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12));

    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24));

    glBindVertexArrayOES(0);

    And after the buffering I bind the texture name to the attrib array.
    tempAttrib.effect.texture2d0.name = [tempSprite [getChildTexture:0];
}

And here is the object for the textures:
- (void) setTexture:(NSString*)fileName ofType:(NSString*)type
{   
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];

    NSError *error;

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
													    GLKTextureLoaderOriginBottomLeft,nil];

    texture = [GLKTextureLoader textureWithContentsOfFile:path
													   options:options error:&error];

    if (texture == nil)
	    NSLog(@"Error loading texture: %@", [error localizedDescription]);

    glBindTexture( GL_TEXTURE_2D, texture.name );

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

    tex = [[GLKEffectPropertyTexture alloc] init];
    tex.enabled = YES;
    tex.envMode = GLKTextureEnvModeDecal;
    tex.name = texture.name;

    //glActiveTexture(GL_TEXTURE0);
    //glBindTexture(GL_TEXTURE_2D, 0);
}

#1Vorel512

Posted 12 April 2012 - 06:22 AM

Here is my rendering code:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
   
    Sprites *fgh;
    Attribute_holder *asd;
   
    for (unsigned int i=0; [gManager getAttributeArrayCount]>i; i++)
    {
	    asd = [gManager getAttributeAtIndex:i];
	    if ([asd getShow] == 1)
	    {
		    fgh = [gManager getSpriteAtIndex:[asd getSpriteID]];		   
		    glBindVertexArrayOES([fgh getVertexArray]);
		   
		    glUseProgram(_program);
		    [asd.effect prepareToDraw];
		   
		    glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
		   
		    //for debugging
		    //glDrawArrays(GL_LINE_LOOP, 0, 6);
	    }
    }
}
I am storing the positions, isdisplayable , etc variables in Attribute_holder, and the vertexes and other stuff like textures in Sprites. gManager is my NSMutableArray where I store them like:
attrib0 - sprite0
attrib1 - sprite0
attrib2 - sprite1

I load the vertexes/uvs/normals to a main buffer and the textures to a "child" buffer:
- (void) createBuffers:(unsigned short) num
{
    IndicesArray[0] = 0;
    IndicesArray[1] = 1;
    IndicesArray[2] = 2;
    IndicesArray[3] = 3;
   
    glGenVertexArraysOES(num, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);
   
    glGenBuffers(num, &_vertexBuffer);
    glGenBuffers(num, &_indexBuffer);
   
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
   
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndicesArray), IndicesArray, GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(VectorArray), VectorArray, GL_STATIC_DRAW);
   
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0));
   
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12));
   
    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24));
   
    glBindVertexArrayOES(0);

    And after the buffering I bind the texture name to the attrib array.
    tempAttrib.[color=#448286]effect[/color].[color=#783aa6]texture2d0[/color].[color=#783aa6]name[/color] = [tempSprite [color=#295a5d]getChildTexture[/color]:[color=#3628d3]0[/color]]
}

And here is the object for the textures:
- (void) setTexture:(NSString*)fileName ofType:(NSString*)type
{   
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];
   
    NSError *error;
   
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
													    GLKTextureLoaderOriginBottomLeft,nil];
   
    texture = [GLKTextureLoader textureWithContentsOfFile:path
													   options:options error:&error];
   
    if (texture == nil)
	    NSLog(@"Error loading texture: %@", [error localizedDescription]);
   
    glBindTexture( GL_TEXTURE_2D, texture.name );
   
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
   
    tex = [[GLKEffectPropertyTexture alloc] init];
    tex.enabled = YES;
    tex.envMode = GLKTextureEnvModeDecal;
    tex.name = texture.name;
   
    //glActiveTexture(GL_TEXTURE0);
    //glBindTexture(GL_TEXTURE_2D, 0);
}

PARTNERS