Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
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] Loading multiple Textures  (Read 1035 times)
0 Members and 1 Guest are viewing this topic.
Offline Mr.CodeIt

Senior Devvie


Medals: 2
Projects: 1



« Posted 2014-05-06 02:27:43 »

Following a tutorial, I can load textures. how it looks:

1  
guy = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/guy.png")));


Initialized code ^

now I draw it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
..other stuff
guy.bind();
glBegin(GL_QUADS);
           
                        glTexCoord2f(0, 0); glVertex2i(p.getx(), p.gety()); // Upper-left
                        glTexCoord2f(1, 0); glVertex2i(p.getx() + 150, p.gety()); // Upper-right
                        glTexCoord2f(1, 1); glVertex2i(p.getx() + 150, p.gety() + 150); // Bottom-right
                        glTexCoord2f(0, 1); glVertex2i(p.getx(), p.gety() + 150); // Bottom-left  
                       
            glEnd();


I tried doing the following for another image but I got the same image.(different locations ofcourse)
Offline Longarmx
« Reply #1 - Posted 2014-05-06 02:34:55 »

Are you saying that you wanted two different images in different locations, but both had the same image?
 - If so, then you need to bind the second image before you put in the second set of vertices.

Offline Mr.CodeIt

Senior Devvie


Medals: 2
Projects: 1



« Reply #2 - Posted 2014-05-06 02:44:47 »

Are you saying that you wanted two different images in different locations, but both had the same image?
 - If so, then you need to bind the second image before you put in the second set of vertices.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
       guy.bind();
glBegin(GL_QUADS);
           
                        glTexCoord2f(0, 0); glVertex2i(p.getx(), p.gety()); // Upper-left
                        glTexCoord2f(1, 0); glVertex2i(p.getx() + 150, p.gety()); // Upper-right
                        glTexCoord2f(1, 1); glVertex2i(p.getx() + 150, p.gety() + 150); // Bottom-right
                        glTexCoord2f(0, 1); glVertex2i(p.getx(), p.gety() + 150); // Bottom-left  
                       
            glEnd();

    //Would I call the same thing just differently for the image
      guy2.bind();
          glBegin(GL_QUADS);
           
                        glTexCoord2f(0, 0); glVertex2i(p.getx(), p.gety()); // Upper-left
                        glTexCoord2f(1, 0); glVertex2i(p.getx() + 150, p.gety()); // Upper-right
                        glTexCoord2f(1, 1); glVertex2i(p.getx() + 150, p.gety() + 150); // Bottom-right
                        glTexCoord2f(0, 1); glVertex2i(p.getx(), p.gety() + 150); // Bottom-left  
                       
            glEnd();
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr.CodeIt

Senior Devvie


Medals: 2
Projects: 1



« Reply #3 - Posted 2014-05-06 02:50:21 »

nevermind I figured it out. I called the bind methods in the wrong place  Undecided
Offline Longarmx
« Reply #4 - Posted 2014-05-06 02:51:09 »

Yes. But you would want to change your coordinates to be in the position of the second guy. Else, you will have two images drawn exactly on top of each other.

How it works is your glBegin() command tells the GPU that this is vertex data (texture coords, position coords, etc). The glEnd() stops this. Your GPU rasterizes this data (makes a shape out of it) and applies a texture to it based on the texture coordinates you passed. This uses the currently bound texture. So, when you bind a new texture, all the glBegin() & glEnd() calls will use that texture until you bind a new one.

I saw that you fixed this but I figured that I would just post it for you to read.

Offline Mr.CodeIt

Senior Devvie


Medals: 2
Projects: 1



« Reply #5 - Posted 2014-05-06 15:50:00 »

How it works is your glBegin() command tells the GPU that this is vertex data (texture coords, position coords, etc). The glEnd() stops this. Your GPU rasterizes this data (makes a shape out of it) and applies a texture to it based on the texture coordinates you passed. This uses the currently bound texture. So, when you bind a new texture, all the glBegin() & glEnd() calls will use that texture until you bind a new one.


What does GPU stand for? I've seen you use it a few times
Offline Longarmx
« Reply #6 - Posted 2014-05-06 17:12:48 »

A quick google told me that it stands for graphic processing unit. It's just your graphics card. If you ever hear the term "hardware acceleration" then that is referencing using the graphics card. Your graphics card is like your CPU, it processes data, and then is able to put that on your screen.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
cybrmynd (137 views)
2017-08-02 12:28:51

cybrmynd (157 views)
2017-08-02 12:19:43

cybrmynd (151 views)
2017-08-02 12:18:09

Sralse (167 views)
2017-07-25 17:13:48

Archive (640 views)
2017-04-27 17:45:51

buddyBro (764 views)
2017-04-05 03:38:00

CopyableCougar4 (1297 views)
2017-03-24 15:39:42

theagentd (1262 views)
2017-03-24 15:32:08

Rule (1235 views)
2017-03-19 12:43:22

Rule (1310 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!