Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  Rectangles not drawn after Texture is initialized  (Read 2076 times)
0 Members and 1 Guest are viewing this topic.
Offline AppleSauce
« Posted 2014-06-12 20:33:18 »

I made 2 rectangles; one follows your mouse, and the other just sits in the upper right hand corner of your screen.

How the rectangles are drawn:
1  
2  
3  
4  
5  
6  
//mouse rect
            glColor3f(10, 10, 10);
            glRectf( Mouse.getX() - 5, Display.getHeight() - Mouse.getY() - 5, Mouse.getX() + 10, Display.getHeight() - Mouse.getY() + 10);
           
            //other rect
            glRectf(100, 100, 10, 10);


The rectangles are there until I initialize the textures:

1  
Img = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Image.png"));


The current GL11 functions I have enabled are :

1  
2  
3  
4  
5  
glEnable(GL_TEXTURE_2D);
     
      //Makes transparent images
      glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);


And I also clear the buffer bits:

1  
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);


I'm using immediate mode until I get a better understanding of how FBO and VBO works.(If you were wondering)
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2014-06-12 20:58:17 »

Define texcoords.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline AppleSauce
« Reply #2 - Posted 2014-06-12 22:41:37 »

Ha. But I didn't actually draw the texture yet. When I do it gets rid of the rectangle. That's the problem.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SilverTiger

JGO Coder


Medals: 41
Exp: 3 years


がんばってください!


« Reply #3 - Posted 2014-06-12 23:23:06 »

Ha. But I didn't actually draw the texture yet. When I do it gets rid of the rectangle. That's the problem.
Do you bind your texture? Roll Eyes
And instead of
glRectf(x1, y1, x2, y2)
you could try this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
// Note: This method assumes that x1 < x2 and y1 < y2, and also that the texture origin is bottom left.
public void drawRect(float x1, float y1, float x2, float y2) {
    glBegin(GL_QUADS);
        glTexCoord2f(0f, 0f);
        glVertex2f(x1, y1);
        glTexCoord2f(1f, 0f);
        glVertex2f(x2, y1);
        glTexCoord2f(1f, 1f);
        glVertex2f(x2, y2);
        glTexCoord2f(0f, 1f);
        glVertex2f(x1, y2);
    glEnd();
}

Before calling
drawRect(x1, x2, y1, y2)
you should do
glBindTexture(GL_TEXTURE_2D, textureId)
.
Does that solve your problem? Smiley

Offline Longarmx
« Reply #4 - Posted 2014-06-15 16:00:04 »

Maybe disable textures when you draw the rectangles?

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5501 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5761 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

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

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

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

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

nelsongames (5113 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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
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!