Reading shaders from text file

I am reading a file using SDL but the string it returns doesn’t work
properly in my shader, it renders a black screen. Here’s the read file
function

SDL_RWops io = SDL_RWFromFile(file_path, “r”);
char
line = NULL;
if (io != NULL)
{
char name[1];
size_t amnt_read = 0;
size_t index = 0;
size_t buffer = 4096;
line = (char*)malloc(sizeof(char) * buffer);
while( amnt_read = SDL_RWread(io, name, sizeof (name), 1) > 0)
{
line[index] = (char)name[0];
++index;
if(index == buffer -1)
{
buffer = buffer * 2;
line = realloc(line, buffer);
SDL_Log("\nreallocing %zu\n", buffer);
}
}
line = realloc(line, (sizeof(char) * index));
line[index] = ‘\0’;
SDL_RWclose(io);
} else { SDL_Log("----------- Android ------------ FAILED TO LOAD
RESOURCE |\t%s\t|",file_path); }
return line;

I’ve tried all these formats of writing a shader to a file:
http://pastebin.com/ThMrtcVR

I hope that I can solve this, for now I just hardcode the shader into the
src file before accessing it.

On the same line I have one more question. Writing shaders for desktop with
layout, in and out then rewriting the same code for gles with varying,
attribute etc, does SDL provide a way to abstract that away?

Have you checked what glGetShaderInfoLog() has to say?

SDL does not currently have any abstraction (or interface, for that matter)
for shaders. You’ll have to either write multiple versions of the same
shaders or write your own translation layer.

Jonny DOn Tue, Aug 18, 2015 at 11:28 AM, Owen Alanzo Hogarth wrote:

I am reading a file using SDL but the string it returns doesn’t work
properly in my shader, it renders a black screen. Here’s the read file
function

SDL_RWops io = SDL_RWFromFile(file_path, “r”);
char
line = NULL;
if (io != NULL)
{
char name[1];
size_t amnt_read = 0;
size_t index = 0;
size_t buffer = 4096;
line = (char*)malloc(sizeof(char) * buffer);
while( amnt_read = SDL_RWread(io, name, sizeof (name), 1) > 0)
{
line[index] = (char)name[0];
++index;
if(index == buffer -1)
{
buffer = buffer * 2;
line = realloc(line, buffer);
SDL_Log("\nreallocing %zu\n", buffer);
}
}
line = realloc(line, (sizeof(char) * index));
line[index] = ‘\0’;
SDL_RWclose(io);
} else { SDL_Log("----------- Android ------------ FAILED TO LOAD
RESOURCE |\t%s\t|",file_path); }
return line;

I’ve tried all these formats of writing a shader to a file:
http://pastebin.com/ThMrtcVR

I hope that I can solve this, for now I just hardcode the shader into the
src file before accessing it.

On the same line I have one more question. Writing shaders for desktop
with layout, in and out then rewriting the same code for gles with varying,
attribute etc, does SDL provide a way to abstract that away?


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

Hi Jonny D

Thanks for the info, helped me sort out the issues. I might have to write a
light gl core to es translator.On Tue, Aug 18, 2015 at 11:37 PM, Jonathan Dearborn wrote:

Have you checked what glGetShaderInfoLog() has to say?

SDL does not currently have any abstraction (or interface, for that
matter) for shaders. You’ll have to either write multiple versions of the
same shaders or write your own translation layer.

Jonny D

On Tue, Aug 18, 2015 at 11:28 AM, Owen Alanzo Hogarth <@Owen_Alanzo_Hogarth wrote:

I am reading a file using SDL but the string it returns doesn’t work
properly in my shader, it renders a black screen. Here’s the read file
function

SDL_RWops io = SDL_RWFromFile(file_path, “r”);
char
line = NULL;
if (io != NULL)
{
char name[1];
size_t amnt_read = 0;
size_t index = 0;
size_t buffer = 4096;
line = (char*)malloc(sizeof(char) * buffer);
while( amnt_read = SDL_RWread(io, name, sizeof (name), 1) > 0)
{
line[index] = (char)name[0];
++index;
if(index == buffer -1)
{
buffer = buffer * 2;
line = realloc(line, buffer);
SDL_Log("\nreallocing %zu\n", buffer);
}
}
line = realloc(line, (sizeof(char) * index));
line[index] = ‘\0’;
SDL_RWclose(io);
} else { SDL_Log("----------- Android ------------ FAILED TO LOAD
RESOURCE |\t%s\t|",file_path); }
return line;

I’ve tried all these formats of writing a shader to a file:
http://pastebin.com/ThMrtcVR

I hope that I can solve this, for now I just hardcode the shader into the
src file before accessing it.

On the same line I have one more question. Writing shaders for desktop
with layout, in and out then rewriting the same code for gles with varying,
attribute etc, does SDL provide a way to abstract that away?


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