opengl - LWJGL - Interleaved VAO/VBO not texturing -


i have been attempting transition game's prototype renderer it's immediate mode testing implementation actual vao/vbo implementation. vbo rendering on screen, refusing texture. below simplest test class shows problem:

public static void main(string[] args) throws exception {      //                          vertx,verty         texx,  texy     float[] data = new float[] {0.0f, 0.0f,     0.25f, 0.75f,                                 0.0f, 64.0f,    0.25f, 1.0f,                                 64.0f, 64.0f,   0.5f, 1.0f,                                  0.0f, 0.0f,     0.25f, 0.75f,                                 64.0f, 64.0f,   0.5f, 1.0f,                                 64.0f, 0.0f,    0.5f, 0.75f};      glfwseterrorcallback(glfwerrorcallback.createprint(system.err));     if (!glfwinit())         throw new illegalstateexception("unable initialize glfw");      long window = glfw.glfwcreatewindow(1600, 900, "test", 0, 0);     glfw.glfwmakecontextcurrent(window);      gl.createcapabilities();      glmatrixmode(gl_projection);     glloadidentity();     glortho(0, 1600, 900, 0, 0.000001, 100);      glmatrixmode(gl_modelview);     glloadidentity();      glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);      int vboid = glgenbuffers();     int vaoid = glgenvertexarrays();      glclientactivetexture(gl_texture0);     glenableclientstate(gl_vertex_array);     glenableclientstate(gl_texture_coord_array);      glbindvertexarray(vaoid);     glbindbuffer(gl_array_buffer, vboid);      glbufferdata(gl_array_buffer, data, gl_static_draw);     glvertexattribpointer(0, 2, gl_float, false, 4*float.bytes, 0);     gltexcoordpointer(2, gl_float, 4*float.bytes, 4*float.bytes);      glbindbuffer(gl_array_buffer, 0);     glbindvertexarray(0);      gldisableclientstate(gl_texture_coord_array);        gldisableclientstate(gl_vertex_array);      gltranslatef(50, 50, 0);      texture t = new texture(test.class.getclassloader().getresourceasstream("test/wallfloor.png"));      while (!glfw.glfwwindowshouldclose(window)) {         glfw.glfwpollevents();         glfw.glfwswapbuffers(window);          glclear(gl_depth_buffer_bit | gl_color_buffer_bit);               glclientactivetexture(gl_texture0);             glenableclientstate(gl_vertex_array);             glenableclientstate(gl_texture_coord_array);                glbindvertexarray(vaoid);             glenablevertexattribarray(0);              t.bind();              gldrawarrays(gl_triangles, 0, 6);               gldisablevertexattribarray(0);             glbindvertexarray(0);              gldisableclientstate(gl_texture_coord_array);                gldisableclientstate(gl_vertex_array);              /* equivelent immediate mode code - works             t.bind();              glbegin(gl_triangles);             gltexcoord2f(0.25f, 0.75f);             glvertex2f(0, 0);             gltexcoord2f(0.25f, 1f);             glvertex2f(0, 64);             gltexcoord2f(0.5f, 0.75f);             glvertex2f(64, 0);              gltexcoord2f(0.5f, 1f);             glvertex2f(64, 64);             gltexcoord2f(0.25f, 1f);             glvertex2f(0, 64);             gltexcoord2f(0.5f, 0.75f);             glvertex2f(64, 0);             glend();             */      } } 

the texture bind call following (where wrap = gl_repeat , filter = gl_nearest):

public void bind() {     glactivetexture(gl_texture0);     glclientactivetexture(gl_texture0);     glenable(gl_texture_2d);     glbindtexture(target, id);     gltexparameteri(target, gl_texture_min_filter, filter);     gltexparameteri(target, gl_texture_mag_filter, filter);     gltexparameteri(target, gl_texture_wrap_s, wrap);     gltexparameteri(target, gl_texture_wrap_t, wrap); } 

having spent weekend googling not finding answer, doing horribly wrong? have tested using immediate mode, still render texture.

in addition, mixing core profile code (glvertexattribpointer) non-core profile (gltexcoordpointer)

but real problem comes wrong stride , offset used. stride defines how large data of 1 vertex is, while offset specifies how far beginning of each vertex actual data starts. in case, every vertex consists of 4 floats stride has 4 * float.bytes. positions first 2 floats in each vertex (offset 0) while texture coordinates 3rd , 4th floats means offset = 2 * float.bytes. correct code somehow (note usage of glvertexpointer instead of glvertexattribpointer):

glvertexpointer(2, gl_float, false, 4*float.bytes, 0); gltexcoordpointer(2, gl_float, 4*float.bytes, 2*float.bytes); 

edit

the usage of vaos wrong. in initialization store glvertexpointer/gltexcoordpointer vao vaoid. in rendering code bind vao 0 instead. attribute settings not present when drawing. in addition, i'm not absolutely sure whether vaos work fixed function calls. in case can remove of vao calls.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -