Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL/OpenGL scaling textures weirdly  (Read 449 times)
0 Members and 1 Guest are viewing this topic.
Offline juliand665

Innocent Bystander





« Posted 2014-01-20 18:08:22 »

I am making a platformer which I started developing with default java functions, but now am switching to OpenGL for everything. I have done everything like I always do with OpenGL, and what I did works fine in my other OpenGL projects. Now my problem is that LWJGL/OpenGL is scaling my textures in a very strange way.
Screenshot and Image to be drawn
It seems to be related to my screen's aspect ratio. (8:5)
I already had to flip the screen to make it the right way around using the following code, but that offsets everything, so I need a fix to that too.
1  
2  
glScalef(1.0f, -1.0f, 1.0f);
glTranslatef(0f, -720f, 0f);

(this is what happens when I don't flip)
But as you can see the text is working fine, it's just the textured rect, and it isn't even straight on the bottom.
I have uploaded my two files containing OpenGL code to PasteBin. Metamorph.java: http://pastebin.com/Lz9tEt5f and Renderer.java: http://pastebin.com/9FJMwM9u
Here are the most relevant snippets from those two classes:

Metamorph.java (main class)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
    public static void initGL()
    {
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glMatrixMode(GL_MODELVIEW);
            glClearColor(0, 0, 0, 1);
            glDisable(GL_DEPTH_TEST);
    }

    public void render()
    {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glLoadIdentity();
            glScalef(1.0f, -1.0f, 1.0f);
            glTranslatef(0f, -720f, 0f);
            //glScalef(1280f/800, 720f/500, 1f);

            renderer.render();

            Display.update();
            Display.sync(60);
    }

Renderer.java (rendering stuff)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
    private void renderMainMenuWithGL()
    {
            //System.out.println("Main Menu!");

            glColor4f(1, 1, 1, 1);

            try
            {
                    Texture bg = loadTexture("mockery");
                    bg.bind();
            } catch (Exception e)
            {
                    e.printStackTrace();
            }

            //drawQuad(0, 0, 1280, 720, 0, 0, 1280, 720);
            glPushMatrix();
            {
                    glBegin(GL_QUADS);
                    glTexCoord2f(0, 0);glVertex2f(0, 0);
                    glTexCoord2f(0, 1);glVertex2f(0, 720);
                    glTexCoord2f(1, 1);glVertex2f(1280, 720);
                    glTexCoord2f(1, 0);glVertex2f(1280, 0);
                    glEnd();
            }
            glPopMatrix();

            TrueTypeFont f = loadFont(MAINFONT, Font.PLAIN, 50);
            TrueTypeFont fb = loadFont(MAINFONT, Font.PLAIN, 48);

            int sel = -1;
            if(Mouse.getX() > 1000 && Mouse.getX() < 1240 && Mouse.getY() > 282.5F && Mouse.getY()< 737.5F)
                    sel = Math.round((Mouse.getY() - 337.5F)/75F);

Just ignore the times I used 1280 and 720 instead of the actual Display methods.
I am also open to advice on file structure/what I did wrong elsewhere, but keep in mind this is heavily WIP
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (20 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (46 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (69 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (46 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!