• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Vorel512

Texture repeating results in black objects

10 posts in this topic

Hi,

I've set up an image loading function, and when I want to repeat some textures, only black objects are rendered.

Here is my code: (the texture variable is GLKTextureInfo)
[CODE]
- (void) setTexture:(NSString*)fileName ofType:(NSString*)type
{
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];

NSError *error;

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:GLKTextureLoaderOriginBottomLeft];


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

if (texture == nil)
NSLog(@"Error loading texture: %@", [error localizedDescription]);
glActiveTexture(GL_TEXTURE0);
glBindTexture( GL_TEXTURE_2D, texture.name );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

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

}
[/CODE]

Any help or suggestion is welcome!
0

Share this post


Link to post
Share on other sites
i would use glTexParameteri for integer not float
did you try to set
GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER
to GL_LINEAR ?

[code]glTexParameteri(GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_MIN_FILTER,GL_LINEAR);[/code]
0

Share this post


Link to post
Share on other sites
[CODE]

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);
[/CODE]

This does not helped the problem, the black stuff stays.
I've tried to put the bind after the texparams, and removed the activetexture, but these steps also did not help.

Thanx for the reply JoJoSim1!
0

Share this post


Link to post
Share on other sites
My texture is 400x360, but I've tried it with 32x32 and the problem still remains.
I do not get the point why should I change the color, the color is grey, and the object I want to texture is at z position -0.6 and it is a rectangle, which I would like to (repeatedly) texture. I can see the gray background on the sides of the picture rectangle.
0

Share this post


Link to post
Share on other sites
glColor can be used to tint your texture with glColor this results to black texture.
Your setup looks correct to me. Maybe you could post your rendering code.
I'm wondering why the gray sides a noticeable.
0

Share this post


Link to post
Share on other sites
Here is my rendering code:
[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);
}
}
}
[/CODE]
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:
[CODE]
- (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];
}
[/CODE]

And here is the object for the textures:
[CODE]
- (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);
}
[/CODE]

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

Share this post


Link to post
Share on other sites
Okay, so...

If I put the texture parameters before the texture creation the scene renders perfect.
I assume, that GLKTextureLoader "lock" the params.
0

Share this post


Link to post
Share on other sites
[quote name='Vorel512' timestamp='1334574713' post='4931687']
Okay, so...

If I put the texture parameters before the texture creation the scene renders perfect.
I assume, that GLKTextureLoader "lock" the params.
[/quote]

You mean, you put your glTexParameteri calls to occur before the calls to glBindTexture and/or the line [GLKTextureLoader textureWithContentsOfFile... ? This will result in the glTexParameteri calls applied to whatever old texture that happened to be bound to GL_TEXTURE_2D, and not the new texture you loaded.

In OpenGL ES, to enable GL_REPEAT, the texture MUST have width and height power of 2. If not, GLES is specified to give [b]silent failure[/b] at your face, and read black from the texture instead. See the Notes part at [url="http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml"]glTexParameter[/url] documentation pages to confirm this.

With your original code, try replacing GL_REPEAT with GL_CLAMP_TO_EDGE to test that the texture will then render properly.
0

Share this post


Link to post
Share on other sites
[quote name='clb' timestamp='1334599156' post='4931800']
[quote name='Vorel512' timestamp='1334574713' post='4931687']
Okay, so...

If I put the texture parameters before the texture creation the scene renders perfect.
I assume, that GLKTextureLoader "lock" the params.
[/quote]

You mean, you put your glTexParameteri calls to occur before the calls to glBindTexture and/or the line [GLKTextureLoader textureWithContentsOfFile... ? This will result in the glTexParameteri calls applied to whatever old texture that happened to be bound to GL_TEXTURE_2D, and not the new texture you loaded.

In OpenGL ES, to enable GL_REPEAT, the texture MUST have width and height power of 2. If not, GLES is specified to give [b]silent failure[/b] at your face, and read black from the texture instead. See the Notes part at [url="http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml"]glTexParameter[/url] documentation pages to confirm this.

With your original code, try replacing GL_REPEAT with GL_CLAMP_TO_EDGE to test that the texture will then render properly.
[/quote]
Hi clb!

My problem were solved! By the way thanks for the reply!!!!!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0