Sign in to follow this  
pescador

OpenGL Texture detail changing by itself [solved]

Recommended Posts

pescador    100
Hello everybody! This is my first opengl experiment and I'm trying to make a simple 2D game. The problem is: The "floor" texture is getting very ugly. In other words, it's getting from this: http://i38.tinypic.com/2chp4p3.jpg to this: http://i33.tinypic.com/35bccbt.jpg . It becomes like that when the floor moves very fast (so when it's freezed it gets like the last picture), but when it moves not so fast it stays ok. One more thing, the floor moves through the texture matrix (glTranslatef). Thankyou in advance! [Edited by - pescador on November 10, 2009 9:59:46 AM]

Share this post


Link to post
Share on other sites
Vilem Otte    2938
This is common problem - try to look at fast rotating wheel (I think it is called The Rotating Wheel Phenomenon).

E.g. you have to do some kind of per pixel motion blurring to make illusion of motion and to keep high level image quality ... look at http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html - you might get right idea there ;)

Share this post


Link to post
Share on other sites
pescador    100
Vilem Otte,

Thankyou for posting that link, but I guess you didn't understand what I said. The floor texture gets ugly like that after moving at fast velocity, I mean, after the "motion" (when it's freezed again) it gets ugly.

See the program flow:

-> Floor is freezed (texture is ok);
-> Floor is moving (texture is bad, as it suposed to be);
-> Floor is freezed again (texture is still bad, why?);
-> Floor is moving very fast (texture is much bad);
-> Floor is freezed again (texture is still much bad);

Sorry for my english.

Share this post


Link to post
Share on other sites
pescador    100
RDragon1,

Yes. Btw the problem is gone when I take off this line (GL_TEXTURE matrix mode):

glTranslatef((GLfloat) cos(rot), (GLfloat) sin(rot), 0);

So maybe it is a "loss of precision in texture coordinates". But now I can't make my car get velocity... Any idea?

Share this post


Link to post
Share on other sites
dpadam450    2357
You are doing something very wrong. You should not be using GL_TEXTURE_MATRIX.

You should be using GL_MODELVIEW_MATRIX. In other words if you have a terrain, when running on it, does the grass move across the terrain, or does the terrain move as a whole?

Share this post


Link to post
Share on other sites
Trienco    2555
Quote:
Original post by dpadam450
You are doing something very wrong. You should not be using GL_TEXTURE_MATRIX.

You should be using GL_MODELVIEW_MATRIX. In other words if you have a terrain, when running on it, does the grass move across the terrain, or does the terrain move as a whole?


Computer graphics isn't about conceptually simulating the real world if there are better ways to achieve the same result. In this case however I remember it is generally advices not to use the texture matrix for performance reasons (probably optimized away if identity). Instead of a screen-sized quad and a moving texture you need to move the quad (or car and "camera", which has the same end result).

It also means more trouble doing an "infinite" world (texture wrapping does that automatically) and always checking the bounds.

The texture matrix is easier and more convenient, but the result looks like either filtering and zooming a low res texture, not clearing the color/depth buffer before each frame or some weird scaling going on. For debugging, read back the texture matrix and make sure it is orthonormal.

Share this post


Link to post
Share on other sites
pescador    100
So it's not convenient to use TEXTURE matrix mode to make the world (floor) move. But why? So the texture matrix mode is less eficient than the others matrix? If yes, how to make an infinite world moving using not infinite quads? Maybe creating an giant quad (size of the game world) using GL_REPEAT wrap mode for the rendering texture and moving it in MODELVIEW matrix mode... Well, In my opinion this is a great loss of performance. What you think?

Thankyou for helping me!

Share this post


Link to post
Share on other sites
pescador    100
Well, I tested it.

1- Move the floor by rendering a textured screen size quad through texture matrix translation;
2- Move the floor by rendering a giant quad (game world size) textured with GL_REPEAT wrap mode, with modelview translation;

Conclusion: the frame rate is the same.
The difference is: in the first option the texture looks, after some time, ugly.

Maybe someone can make a deeper test. Thanks!

Share this post


Link to post
Share on other sites
szecs    2990
I use the texture moving technique (to simulate the track of a tank), and I didn't notice this phenomenon.
Anyway you can use the following with modelview transformation:
Make a quad and repeat the texture 2 times (-1 to 1 texture coordinate range).
The size of the quad is to times bigger, than the size of the screen.

if you translate the map and rotate the car (like in GTA 1):

Let x, y be the coordinates of the quad center in screen coordinates.

if( x > screen_width )
x -= screen_width;
else if( x < screen_width )
x += screen_width;

if( y > screen_height )
y -= screen_height;
else if( y < screen_height )
y += screen_height;

I hope that made sense.

Share this post


Link to post
Share on other sites
pescador    100
The code has no secrets, it's just like this:


glMatrixMode(GL_TEXTURE);
glTranslatef(floor.xpos, floor.ypos, 0);
//render the floor with display list or vertex array (I got the same frame rate).
glLoadIdentity();
//render the car. Want it to stay centered.
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//render some objects.
glPopMatrix();

Share this post


Link to post
Share on other sites
szecs    2990
What values do floor.xpos, floor.ypos have?

Do you convert it to texture space, or you have say x = 42345312454744?

Maybe it's simply a floating point precision problem.

Maybe the car only seems to have proper speed because of this:
You except to translate it with 0.1, instead it translates with 321321321.1.
So it displays just like it was 0.1 (because the repeat warping), but you loose precision.

EDITED it heavily.

Share this post


Link to post
Share on other sites
pescador    100
Well, actually xpos and ypos are defined as GLfloat. And they are "zero initialized". The increment function: obj.xpos += 0.001; I really don't know what to do. Maybe my graphic card (Btw Sis Mirage 3, onboard) is the trouble.

Share this post


Link to post
Share on other sites
pescador    100
So, I would like to say this problem is partially solved. I just change the floor move type, from texture matrix mode to modelview matrix mode. The texture didn't currupt its appearence anymore.

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  

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now