OpenGL Texture

Hello!
I’m using the latest version of SDL2. Also SDL2_image.
In my rendering code I try to use a texture in a GL_QUAD:

{
glClear(GL_COLOR_BUFFER_BIT);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);

glVertexPointer(2, GL_FLOAT, 0, (GLvoid*) sCardQuad);
glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*) sTexCoords);
SDL_GL_BindTexture(sTextures[0][0], NULL, NULL);

glBegin(GL_QUADS);
    glArrayElement(0);
    glArrayElement(1);
    glArrayElement(2);
    glArrayElement(3);
glEnd();

SDL_GL_UnbindTexture(sTextures[0][0]);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

SDL_GL_SwapWindow(m_pWindow);

}

But only the quad without texture is being drawn.
sTextures is a matrix of SDL_Texture* loaded successfully with IMG_Load.
I saw in opengl renderer that SDL_Texture does the glGenTexture calling and all. So I just need to bind it, right?

Thank you!

Hi,

I’ve never used SDL_Texture*'s while rendering with OpenGL, however I can
tell you that you need a GLuint to be used when binding an active texture.
This GLuint needs to be obtained when calling glGenTextures. So even if
SDL_Texture’s initialization (which you don’t show, so we can’t assume
you’re doing it right) is correct, the struct itself, or a pointer to it,
is not the correct thing to bind. If you want, you can try to call
glGenTextures yourself, and use the result of that for your binding step,
and that might help you find out where things are breaking.

Good luck.

ChristianOn Mon, Feb 25, 2013 at 8:58 PM, Felipe - wrote:

Hello!
I’m using the latest version of SDL2. Also SDL2_image.
In my rendering code I try to use a texture in a GL_QUAD:

{
glClear(GL_COLOR_BUFFER_BIT);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);

glVertexPointer(2, GL_FLOAT, 0, (GLvoid*) sCardQuad);
glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*) sTexCoords);
SDL_GL_BindTexture(sTextures[0][0], NULL, NULL);

glBegin(GL_QUADS);
    glArrayElement(0);
    glArrayElement(1);
    glArrayElement(2);
    glArrayElement(3);
glEnd();

SDL_GL_UnbindTexture(sTextures[0][0]);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

SDL_GL_SwapWindow(m_pWindow);

}

But only the quad without texture is being drawn.
sTextures is a matrix of SDL_Texture* loaded successfully with IMG_Load.
I saw in opengl renderer that SDL_Texture does the glGenTexture calling
and all. So I just need to bind it, right?

Thank you!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Not a response to the original poster, but I do have a correction.> Date: Tue, 26 Feb 2013 09:39:44 -0500

From: Christian Leger <chrism.leger at gmail.com>
To: SDL Development List
Subject: Re: [SDL] OpenGL Texture
Message-ID:
<CAHgimD__yBC0U76woaBL+ZvwwD8QN9TxKoGUr1jUYagKT2u6rQ at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”

Hi,

I’ve never used SDL_Texture*'s while rendering with OpenGL, however I can
tell you that you need a GLuint to be used when binding an active texture.
This GLuint needs to be obtained when calling glGenTextures. So even if
SDL_Texture’s initialization (which you don’t show, so we can’t assume
you’re doing it right) is correct, the struct itself, or a pointer to it,
is not the correct thing to bind.

SDL_GL_BindTexture takes a SDL_Texture pointer, not a GLuint. The
documentation is here:
http://wiki.libsdl.org/moin.cgi/SDL_GL_BindTexture

Behind the scenes it just binds the OpenGL texture (SDL itself has
access to the GLuint), so it basically works just like OpenGL from
that point on. Here’s the implementation file:
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/SDL_render.c

I believe that these provide relevant files as well:
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengl/SDL_render_gl.c
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles/SDL_render_gles.c
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles2/SDL_render_gles2.c

The relevant functions are near the very top (for the function loaders
of the last three) and bottom (for the bind functions of all four).

Yes, thank you for answering.
That’s exacly what I was thinking.
I’m not passing GLuint’s, as mentioned, they are matrixes of SDL_Texture*.> Date: Tue, 26 Feb 2013 22:10:35 -0600

From: absinthdraco at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] OpenGL Texture

Not a response to the original poster, but I do have a correction.

Date: Tue, 26 Feb 2013 09:39:44 -0500
From: Christian Leger <chrism.leger at gmail.com>
To: SDL Development List
Subject: Re: [SDL] OpenGL Texture
Message-ID:
<CAHgimD__yBC0U76woaBL+ZvwwD8QN9TxKoGUr1jUYagKT2u6rQ at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”

Hi,

I’ve never used SDL_Texture*'s while rendering with OpenGL, however I can
tell you that you need a GLuint to be used when binding an active texture.
This GLuint needs to be obtained when calling glGenTextures. So even if
SDL_Texture’s initialization (which you don’t show, so we can’t assume
you’re doing it right) is correct, the struct itself, or a pointer to it,
is not the correct thing to bind.

SDL_GL_BindTexture takes a SDL_Texture pointer, not a GLuint. The
documentation is here:
http://wiki.libsdl.org/moin.cgi/SDL_GL_BindTexture

Behind the scenes it just binds the OpenGL texture (SDL itself has
access to the GLuint), so it basically works just like OpenGL from
that point on. Here’s the implementation file:
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/SDL_render.c

I believe that these provide relevant files as well:
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengl/SDL_render_gl.c
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles/SDL_render_gles.c
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles2/SDL_render_gles2.c

The relevant functions are near the very top (for the function loaders
of the last three) and bottom (for the bind functions of all four).


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ah, I see, my mistake. My eye caught ‘bindtexture’ but missed the SDL_GL
part. Apologies.On Wed, Feb 27, 2013 at 12:00 AM, Felipe - wrote:

Yes, thank you for answering.
That’s exacly what I was thinking.
I’m not passing GLuint’s, as mentioned, they are matrixes of SDL_Texture*.

Date: Tue, 26 Feb 2013 22:10:35 -0600
From: absinthdraco at gmail.com
To: sdl at lists.libsdl.org

Subject: Re: [SDL] OpenGL Texture

Not a response to the original poster, but I do have a correction.

Date: Tue, 26 Feb 2013 09:39:44 -0500
From: Christian Leger <@Christian_Leger>
To: SDL Development List
Subject: Re: [SDL] OpenGL Texture
Message-ID:
<CAHgimD__yBC0U76woaBL+ZvwwD8QN9TxKoGUr1jUYagKT2u6rQ at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”

Hi,

I’ve never used SDL_Texture*'s while rendering with OpenGL, however I
can

tell you that you need a GLuint to be used when binding an active
texture.

This GLuint needs to be obtained when calling glGenTextures. So even if
SDL_Texture’s initialization (which you don’t show, so we can’t assume
you’re doing it right) is correct, the struct itself, or a pointer to
it,

is not the correct thing to bind.

SDL_GL_BindTexture takes a SDL_Texture pointer, not a GLuint. The
documentation is here:
http://wiki.libsdl.org/moin.cgi/SDL_GL_BindTexture

Behind the scenes it just binds the OpenGL texture (SDL itself has
access to the GLuint), so it basically works just like OpenGL from
that point on. Here’s the implementation file:
http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/SDL_render.c

I believe that these provide relevant files as well:

http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengl/SDL_render_gl.c

http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles/SDL_render_gles.c

http://hg.libsdl.org/SDL/file/bb6a9d41d737/src/render/opengles2/SDL_render_gles2.c

The relevant functions are near the very top (for the function loaders
of the last three) and bottom (for the bind functions of all four).


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org