Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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 2559 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  
 
 

 
EgonOlsen (1668 views)
2018-06-10 19:43:48

EgonOlsen (1705 views)
2018-06-10 19:43:44

EgonOlsen (1156 views)
2018-06-10 19:43:20

DesertCoockie (1584 views)
2018-05-13 18:23:11

nelsongames (1184 views)
2018-04-24 18:15:36

nelsongames (1708 views)
2018-04-24 18:14:32

ivj94 (2532 views)
2018-03-24 14:47:39

ivj94 (1757 views)
2018-03-24 14:46:31

ivj94 (2834 views)
2018-03-24 14:43:53

Solater (970 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!