Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 Rectangle Textures (new to openGl)  (Read 1160 times)
0 Members and 1 Guest are viewing this topic.
Offline zidsal

Senior Newbie





« Posted 2012-12-29 22:06:33 »

ok so I'm trying to make a spritesheet and I'm at the point where I'm trying to only get part of the spritesheet drawn

   
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  
public SpriteSheetSprite(Texture texture, int x, int  y, int maxCol, int maxRows){
      this.texture = texture;
      this.x = x;
      this.y = y;
      this.maxCol = maxCol;
      this.maxRows = maxRows;
           
      glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture.getTextureID());
      //texture.bind();
  }

   @Override
   public void Render() {
      glBegin(GL_QUADS);
         glTexCoord2f(0,0);
         glVertex2i(x,y);//top left
        glTexCoord2f(32,0);
         glVertex2i(x + getWidth(),y);//top right
        glTexCoord2f(32,32);
         glVertex2i(x+ getWidth(),y + getHeight());//bottem right
        glTexCoord2f(0,32);
         glVertex2i(x,y + getHeight());//bottem left
     glEnd();
     
   }


Using the above code my quad gets an image which is the spritesheet stretched over and over, that is to be expected as we're no longer wrapping the texture around the quad from 0,0 to 1,1

The problem I'm having is that when I switch OpenGl from GL_TEXTURE_2D to GL_TEXTURE_RECTANGLE_ARB the texture no longer wants to be applied to the quad (I just get a white rectangle). Here is my code for initalizing open gl

1  
2  
3  
4  
5  
6  
7  
   private void startOpenGl(){
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0,Settings.WIDTH, Settings.HEIGHT,0,1,-1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_RECTANGLE_ARB);
   }


any help on the matter would be awesome
Offline davedes
« Reply #1 - Posted 2012-12-29 22:11:29 »

  • Texture rectangles are old and no longer necessary -- you should stick to GL_TEXTURE_2D.
  • If you're using SlickUtils (which is also old and crappy..) then you should not call glBindTexture directly, but instead stick with texture.bind() and TextureImpl.bindNone().
  • For that matter, glBegin/glEnd is also old and deprecated... but if you must use it, don't call glBegin and glEnd for each quad. Instead, batch a bunch of quads within a single draw call. Also glBindTexture before you render your quad to be sure you are not binding other textures, rather than only doing it once at creation time.
  • Also note that SlickUtils is based on GL_TEXTURE_2D and doesn't support texture rectangles.
If you are keen to learn things using more "modern GL approaches," see here:
https://github.com/mattdesl/lwjgl-basics/wiki

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.

CopyableCougar4 (9 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!