Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing window with AnimeManager (demo helper) should resize textures #35

Open
Gothor opened this issue May 17, 2023 · 1 comment
Open

Comments

@Gothor
Copy link
Contributor

Gothor commented May 17, 2023

Hi!

Currently, if we use the demo helper with the flag SDL_RESIZABLE and then resize the window, the animation in not well drawn.

This seems to be because the function gl4dhInit() takes two arguments w and h used two creates two textures (for colors and depth).
There should be a way to resize those textures when resizing the window.

Thus, I would suggest to add the following function to gl4dhAnimeManager.c:

void gl4dhResize(int w, int h) {
  _w = w; _h = h;

  // Resize color texture
  glBindTexture(GL_TEXTURE_2D, _wTexId);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

  // Resize depth texture
  glBindTexture(GL_TEXTURE_2D, _wdTexId);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
  
  glBindTexture(GL_TEXTURE_2D, 0);
}

that could then be called the following way:

int main(int argc, char* argv[]) {
  // init...
  gl4duwResizeFunc(resize);
}

void resize(int w, int h) {
  glViewport(0, 0, w, h);
  // stuffs...
  gl4dhResize(w, h);
}

The textures should then be properly resized and fit the window.

Would you allow me to add this feature?
Would there be things to add before? (Like allowing the user to specify a resize function for each animation?)
Should we make sure the textures actually exist before trying to resize them?

@Gothor Gothor changed the title Resizing window in AnimeManager (demo helper) should resize textures Resizing window with AnimeManager (demo helper) should resize textures May 18, 2023
@noalien
Copy link
Owner

noalien commented May 27, 2023

Hi Gothor,

sorry for my late reply,

your proposal sounds good, and I'm happy with the way it's set up. Go for it. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants