Hi Joe, thanks for the answer but this is not the case same result as before, I’m completely certain texture2D is the problem (always returns vec4(0, 0, 0, ?)) to prove this here’s simple shading shader
fragment:
precision highp float;
varying vec4 color;
varying vec2 texCoord;
uniform sampler2D texture;
bool iskeycolor(vec4 c)
{
return c.r > 0.6 && c.g 0.6;
}
void main (void)
{
vec4 tc = texture2D(texture, texCoord);
if(iskeycolor(tc))
discard;
gl_FragColor = vec4(tc.rg, 1.0, 1.0) * color;
}
vertex:
uniform mat4 MVP;
attribute vec4 vbo_Vertex;
attribute vec3 vbo_Normal;
attribute vec2 vbo_TexCoord;
varying vec2 texCoord;
varying vec4 color;
void main(void)
{
float d = min(max(dot(vbo_Normal, vec3(1.0, 1.0, 1.0)), 0.5), 1.0);
color = vec4(d, d, d, 1.0);
texCoord = vbo_TexCoord;
gl_Position = MVP * vbo_Vertex;
}
results in:

as you can see there’s no component other than blue…
Maybe it’s caused by x86 architecture??
here’s the code for jpeg loading but I think it’s ok because I could see the texture data in tracer
static unsigned int make8888(int red, int green, int blue, int alpha)
{
return (unsigned int)(((alpha << 24) & 0xff000000) | ((blue << 16) & 0x00ff0000) | ((green << 8) & 0x0000ff00) | ( red & 0x000000ff));
}
unsigned int* readJPEG(const char* name, int& width, int& height)
{
FH* f = fsopen(name, "rb");
if(!f)
return NULL;
int size = fssize(f);
unsigned char* buffer = (unsigned char *)malloc(size);
fsread(f, buffer, size);
fsclose(f);
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr error;
cinfo.err = jpeg_std_error(&error);
error.error_exit = JPEGError;
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, buffer, size);
jpeg_read_header(&cinfo, true);
jpeg_start_decompress(&cinfo);
width = cinfo.output_width;
height = cinfo.output_height;
int rstride = width * cinfo.output_components;
unsigned int* data = (unsigned int*)calloc(sizeof(unsigned int), width * height);
unsigned int* res = data + (width * height) - width;
JSAMPARRAY rbuffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rstride, 1);
while (cinfo.output_scanline < height)
{
jpeg_read_scanlines(&cinfo, rbuffer, 1);
for(int i = 0, pi = 0; pi < width; i += 3, pi++)
{
//debug("rgb(%d, %d) : %d %d %d", pi, cinfo.output_scanline, rbuffer[0], rbuffer[0], rbuffer[0]);
res[pi] = make8888(rbuffer[0], rbuffer[0], rbuffer[0], 0xFF);
}
res -= width;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
free(buffer);
return data;
}
regards, Petr