• 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
Stephan Picker

Binding a specific Texture Level/Mip-Map

8 posts in this topic

Hey Guys,
 
I'm trying to bind a specific Level of an offscreen-render-texture to let's say texture target 0.
 
Now the default way of binding a texture doesn't allow that, so this is my workaround.
It's ugly, inconsistent and I don't like it.
 

public void bind(int textureId) {
    glActiveTexture(GL_TEXTURE0 + textureId);
    glBindTexture(GL_TEXTURE_2D, textureHandle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
} 

So I found this function "glBindImageTexture", which I still dont' understand.
 

public void bind(int textureId, int level) {
    glBindImageTexture(textureId, textureHandle, level, false, 0, GL_READ_ONLY, GL_RGBA32F);
}

 
 Is this what I want? Do I use it right? Also I can't use formats like GL_RGB32F - without the Alpha channel.
All I get is a grey Rect, when I render this texture with "glBindImageTexture".

Edited by stefthedrummer
0

Share this post


Link to post
Share on other sites

This will bias your textures to use mip maps 2 levels closer to level 0 (it will use 2x higher resolution compared to what it should be using).

GLfloat bias = -2.0;
glTexEnvfv(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, &bias);

 

glTexParameter takes these as inputs, you can push the lowest and highest resolution you want to use. I assume if they are = , it will only use that mip-map level no matter what.

GL_TEXTURE_MIN_LOD,
GL_TEXTURE_MAX_LOD

 

You can also write a shader and call texture2dLod(texture, uv_coords, mipMapLevel)

0

Share this post


Link to post
Share on other sites

It may also depend what you want to do. I don't believe that you can pick a specific level to render to, but the above makes it so you can choose which level to actually sample and texture from.

0

Share this post


Link to post
Share on other sites

Ok, now I tried these functions:

texelFetch(texture, coord, level);
textureLod(texture, coord, level);

and I also set my filters via "glTexParameter()" to

MAG -> GL_LINEAR
MIN -> GL_LINEAR_MIPMAP_NEAREST

but all I get is black pixels.

 

 

I'am absolutely shure that my textures are all-right, because when I render them with with:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);

It views the right level. (I have different colors on each level of my test texture).

		OpenGL.setTexture(0, texture); //(texture unit, textureHandle)
		OpenGL.setProgram(blitProgram);

		blitProgram.setInt("level", level);

		OpenGL.setDepthTest(false);

		glBegin(GL_QUADS);
		glVertexAttrib2f(1, 0.0f, 0.0f);
		glVertexAttrib3f(0, left, bottom, 0.0f);
		glVertexAttrib2f(1, 1.0f, 0.0f);
		glVertexAttrib3f(0, right, bottom, 0.0f);
		glVertexAttrib2f(1, 1.0f, 1.0f);
		glVertexAttrib3f(0, right, top, 0.0f);
		glVertexAttrib2f(1, 0.0f, 1.0f);
		glVertexAttrib3f(0, left, top, 0.0f);
		glEnd();

		OpenGL.setDepthTest(true);
#version 420 core

in  vec2 passCoord;

out vec3 outColor;

uniform sampler2D source;
uniform int       level;

void main()
{
	outColor = textureLod(source, passCoord, level).rgb + vec3(0.1f);
}

#version 420 core

in vec3 inPos;
in vec2 inCoord;
out vec2 passCoord;

void main()
{
	gl_Position = vec4(inPos, 1.0f);

	passCoord = inCoord;
}

Thanks in advance

Edited by stefthedrummer
0

Share this post


Link to post
Share on other sites

I missed it. If you can set it to view the proper levels what is your issue? Sampling them from a shader? If you want to use textureLod, try it without changing the texture parameters. I have used a shader to pick a specific texture level without changing texture parameters.

0

Share this post


Link to post
Share on other sites

Sry, I ment it works when rendering with "texture()" [without Lod] and chaching its base level but it doesn't when using "textureLod" without the baselevel midification. Tomorrow I will try commenting out all parameter changes and see what happens.

0

Share this post


Link to post
Share on other sites

Tomorrow I will try commenting out all parameter changes and see what happens.

 

Doesn't Work.

 

I also just read that you can only use "textureLod" in vertex buffers. Isn't that nonsense?

0

Share this post


Link to post
Share on other sites

No you can only use textureLod , and not texture in vertex shaders. Because you dont use mip-map/ anisotropic filtering when sampling a texture in a vertex shader.

 

You can though use textureLod in a pixel shader.

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