c++ - OpenGL Textures are all black in 3.3 - but work in 3.1 -


i'm working on simple 3d scene in opengl3.3, when trying texture objects - of them textured entirely black. however, if change context version 3.1; has no problem rendering textures correctly on models.

i'm not sure if suggests i'm using deprecated functionality/methods, i'm struggling see problem be.

setting texture

(load texture file) ... glgentextures(1, &texid);               // create texture ( change ) glbindtexture(gl_texture_2d, texid);  glteximage2d(gl_texture_2d, 0, texture_bpp / 8, texture_width, texture_height, 0, texture_type, gl_unsigned_byte, texture_imagedata); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear); gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear); ... 

binding texture render

// mlocation layout location in shader, glgetuniformlocation // mtextureunit specified texture unit load into. using 0. // mtextureid id of loaded texture, generated above. glactivetexture( gl_texture0 + mdata.mtextureunit ); glbindtexture( gl_texture_2d, mdata.mtextureid ); gluniform1i( mlocation, mdata.mtextureunit ); 

fragment shader

uniform sampler2d diffusemap; in vec2 passuv; out vec3 outcolour; ... outcolour = texture( diffusemap, passuv ).rgb; 

all textures being used power of 2, square sizes.


images showing problem.

gl3.1: http://i.imgur.com/nugj6va.png

gl3.3: http://i.imgur.com/ooc0jcd.png


vertex shader

#version 330 core  uniform mat4 p; uniform mat4 v; uniform mat4 m;  in vec3 vertex; in vec3 normal; in vec2 uv;  out vec3 passvertex; out vec3 passnormal; out vec2 passuv;  void main( void ) {     gl_position = p * v * m * vec4( vertex, 1.0 );      passvertex = vec3( m * vec4( vertex, 1.0 ) );     passnormal = vec3( m * vec4( normal, 1.0 ) );     passuv = uv; } 

for sake of completeness, internal format of texture should enumerator. , 1 of sized enumerators, not 1 of unsized ones. please stop using gl_rgb when can use gl_rgb8.

answer correctly identifies issue, helpful have explained why previous assumption work on 3.1 , not on 3.3.

the ability use number on range [1, 4] deprecated in opengl 3.0 , removed in opengl 3.1. however, @ time, there wasn't way say, "give me actual core profile of opengl version 3.1"; wgl/glx_context_core_profile_bit_arbs didn't exist. therefore, when got 3.1 context, legal implementation export arb_compatibility extension, still allowed of removed functionality.

in 3.2, ability explicitly select profile added opengl. @ point, not exposing arb_compatibility in core profile. that's why code works when ask 3.1 (since it's free give 3.1 compatibility), not when ask 3.3 core profile.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -