Sign in to follow this  
pescador

OpenGL Texture detail changing by itself [solved]

Recommended Posts

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
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
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
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
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
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
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
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
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
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
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
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
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  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627638
    • Total Posts
      2978330
  • Similar Content

    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
    • By cebugdev
      hi guys, 
      are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
      Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic 
      let me know if you guys have recommendations.
      Thank you in advance!
    • By dud3
      How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below? 
      Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
      Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.
       
      References:
      Code: https://pastebin.com/Hcshj3FQ
      The video shows the difference between blender and my rotation:
       
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
       
    • By test opty
      Hello all,
       
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now