uiacceltk/hitchcock/backgroundanim/refplugin/src/shader.c
changeset 0 15bf7259bb7c
child 7 433cbbb6a04b
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <string.h>
       
    21 #include <GLES2/gl2.h>
       
    22 #include <sys/syslimits.h>
       
    23 
       
    24 #include "shader.h"
       
    25 
       
    26 
       
    27 GLuint LoadAndCompileShader(char* path, char* shadername, GLenum type)
       
    28     {
       
    29     char filename[PATH_MAX];
       
    30     int len = 0;
       
    31     GLuint shader = 0;
       
    32     GLint compiled = 0;
       
    33     char* shaderdata = NULL;
       
    34     FILE* file;
       
    35     
       
    36     strcpy(filename,path);
       
    37     strcat(filename,"\\");
       
    38     strcat(filename,shadername);
       
    39     file = fopen(filename,"rb");
       
    40     if (!file)
       
    41         {
       
    42         return 0;
       
    43         }
       
    44         
       
    45 
       
    46     fseek (file, 0, SEEK_END);
       
    47     len = ftell (file);
       
    48     fseek(file, 0, SEEK_SET);
       
    49 
       
    50     shaderdata = (char*)malloc(len+1);
       
    51     if (!shaderdata)
       
    52         {
       
    53         fclose(file);
       
    54         return 0;
       
    55         }
       
    56     
       
    57     fread(shaderdata, 1, len, file);
       
    58     fclose(file);
       
    59     shaderdata[len] = 0;
       
    60 
       
    61     
       
    62     shader = glCreateShader(type);
       
    63     glShaderSource(shader, 1, (const char**)&shaderdata,NULL);
       
    64     glCompileShader(shader);
       
    65     glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);    
       
    66     
       
    67     if (!compiled)
       
    68         {
       
    69         char infobuf[ 256 ];
       
    70 
       
    71         glGetShaderInfoLog( shader, 256, NULL, infobuf );
       
    72 
       
    73         glDeleteShader(shader);
       
    74         shader = 0;
       
    75         }
       
    76     free(shaderdata);
       
    77     return shader;
       
    78     }