Rectangles not drawn after Texture is initialized

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:

//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:

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

The current GL11 functions I have enabled are :

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:

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)

Define texcoords.

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? ::slight_smile:
And instead of [icode]glRectf(x1, y1, x2, y2)[/icode] you could try this:


// 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 [icode]drawRect(x1, x2, y1, y2)[/icode] you should do [icode]glBindTexture(GL_TEXTURE_2D, textureId)[/icode].
Does that solve your problem? :slight_smile:

Maybe disable textures when you draw the rectangles?