[LWJGL] Resize Problem

  • Java

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Yissu.

    [LWJGL] Resize Problem

    Hallo Leute,

    Ich hab ein kleines Problem und zwar wenn ich das Fenster meiner Anwendung resize also die Größe ändert verziehen sich die ganzen Quadrate.
    Im Grund will ich eigentlich nur ein Schachspiel machen.

    Ich zeichne das ganze so:

    Java-Quellcode

    1. boolean changed = false;
    2. if(displayWidth != Display.getWidth() || displayHeight != Display.getHeight())
    3. {
    4. glMatrixMode(GL_PROJECTION);
    5. glLoadIdentity();
    6. glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
    7. glMatrixMode(GL_MODELVIEW);
    8. displayWidth = Display.getWidth();
    9. displayHeight = Display.getHeight();
    10. System.out.println("===========================");
    11. System.out.println("Display size was changed!");
    12. System.out.println("Width: " + Display.getWidth());
    13. System.out.println("Height: " + Display.getHeight());
    14. if(displayWidth / 8 < displayHeight / 8 || displayWidth / 8 == displayHeight / 8)
    15. {
    16. blockSize = displayWidth / 8;
    17. } if (displayWidth / 8 > displayHeight / 8) {
    18. blockSize = displayHeight / 8;
    19. }
    20. System.out.println("Blocksize: " + blockSize);
    21. changed = true;
    22. }
    23. glClear(GL_COLOR_BUFFER_BIT);
    24. glClearColor(.5f, .5f, .5f, 1);
    25. glBegin(GL_QUADS);
    26. int id = 0;
    27. for(int y = 0; y < blockSize * 8; y += blockSize)
    28. {
    29. for(int x = 0; x < blockSize * 8; x += blockSize)
    30. {
    31. if(changed)
    32. {
    33. System.out.println("Draw block at " + x + ", " + y);
    34. }
    35. id++;
    36. boolean light = id % 2 != 0;
    37. drawQuad(light ? .9f : 0, light ? .9f : 0, light ? .9f : 0, x, y, blockSize, blockSize);
    38. }
    39. id++;
    40. }
    41. glEnd();


    drawQuad:

    Java-Quellcode

    1. private void drawQuad(float red, float green, float blue, int posX, int posY, int sizeX, int sizeY)
    2. {
    3. glColor3f(red, green, blue);
    4. glVertex2i(posX, posY);
    5. glVertex2i(posX, posY + sizeY);
    6. glVertex2i(posX + sizeX, posY + sizeY);
    7. glVertex2i(posX + sizeX, posY);
    8. }


    Die Ausgabe original lautet:

    Quellcode

    1. ===========================
    2. Display size was changed!
    3. Width: 800
    4. Height: 800
    5. Blocksize: 100
    6. Draw block at 0, 0
    7. Draw block at 100, 0
    8. Draw block at 200, 0
    9. Draw block at 300, 0
    10. Draw block at 400, 0
    11. Draw block at 500, 0
    12. Draw block at 600, 0
    13. Draw block at 700, 0
    14. Draw block at 0, 100
    15. Draw block at 100, 100
    16. Draw block at 200, 100
    17. Draw block at 300, 100
    18. Draw block at 400, 100
    19. Draw block at 500, 100
    20. Draw block at 600, 100
    21. Draw block at 700, 100
    22. Draw block at 0, 200
    23. Draw block at 100, 200
    24. Draw block at 200, 200
    25. Draw block at 300, 200
    26. Draw block at 400, 200
    27. Draw block at 500, 200
    28. Draw block at 600, 200
    29. Draw block at 700, 200
    30. Draw block at 0, 300
    31. Draw block at 100, 300
    32. Draw block at 200, 300
    33. Draw block at 300, 300
    34. Draw block at 400, 300
    35. Draw block at 500, 300
    36. Draw block at 600, 300
    37. Draw block at 700, 300
    38. Draw block at 0, 400
    39. Draw block at 100, 400
    40. Draw block at 200, 400
    41. Draw block at 300, 400
    42. Draw block at 400, 400
    43. Draw block at 500, 400
    44. Draw block at 600, 400
    45. Draw block at 700, 400
    46. Draw block at 0, 500
    47. Draw block at 100, 500
    48. Draw block at 200, 500
    49. Draw block at 300, 500
    50. Draw block at 400, 500
    51. Draw block at 500, 500
    52. Draw block at 600, 500
    53. Draw block at 700, 500
    54. Draw block at 0, 600
    55. Draw block at 100, 600
    56. Draw block at 200, 600
    57. Draw block at 300, 600
    58. Draw block at 400, 600
    59. Draw block at 500, 600
    60. Draw block at 600, 600
    61. Draw block at 700, 600
    62. Draw block at 0, 700
    63. Draw block at 100, 700
    64. Draw block at 200, 700
    65. Draw block at 300, 700
    66. Draw block at 400, 700
    67. Draw block at 500, 700
    68. Draw block at 600, 700
    69. Draw block at 700, 700


    Änder ich jetzt aber die Breite bleiben alle Werte gleich außer die Breite trotzdem ist das ganze Bild verzogen (siehe Screenshot).
    Bilder
    • screen_right.png

      9,71 kB, 802×829, 135 mal angesehen
    • screen_bug.png

      10,56 kB, 1.007×829, 128 mal angesehen
    Das Problem hatte ich auch. Es leigt an OpenGL. Du musst GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1); neu aufrufen, mit den angepassten werten.
    Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.

    BeryJu.org BeryJu.org/Blog