Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7822 in orxonox.OLD for branches/water/src


Ignore:
Timestamp:
May 24, 2006, 6:04:19 PM (19 years ago)
Author:
bensch
Message:

water: shader update

Location:
branches/water/src/lib/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/lib/graphics/shader.cc

    r7818 r7822  
    2020#include "stdlibincl.h"
    2121#include "compiler.h"
    22 #include <stdio.h>
     22//#include <stdio.h>
     23#include <fstream>
     24
    2325#include "debug.h"
    2426
     
    2628
    2729
    28 #ifndef PARSELINELENGHT
    29 #define PARSELINELENGHT     512       //!< how many chars to read at once
     30#ifndef PARSELINELENGTH
     31#define PARSELINELENGTH     512       //!< how many chars to read at once
    3032#endif
    3133
     
    119121
    120122
    121   std::vector<char*>* program = fileReadArray(fileName);
     123  std::string program;
     124  if (!readShader(fileName, program))
     125    return false;
    122126
    123127  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
     
    139143    GLint status = 0;
    140144    /// FIXME do it back
    141     //    glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL);
     145    const char* prog = &program[0];
     146    glShaderSourceARB(shader, 1, &prog, NULL);
    142147    glCompileShaderARB(shader);
    143148    // checking on error.
     
    148153      glAttachObjectARB(this->shaderProgram, shader);
    149154  }
    150   for (unsigned int i=0; i< program->size(); i++)
    151     delete[] (*program)[i];
    152   delete program;
    153155}
    154156
     
    166168
    167169
    168 char* Shader::fileRead(const std::string& fileName)
    169 {
    170   FILE* fileHandle;
    171   char* content = NULL;
    172 
    173   int count = 0;
    174 
    175   if (fileName.empty())
    176     return NULL;
    177 
    178   fileHandle = fopen(fileName.c_str(), "rt");
    179 
    180   if (fileHandle == NULL)
    181     return NULL;
    182   fseek(fileHandle, 0, SEEK_END);
    183   count = ftell(fileHandle);
    184   rewind(fileHandle);
    185   if (count > 0) {
    186      content = new char[count+1];
    187      count = fread(content, sizeof(char), count, fileHandle);
    188      content[count] = '\0';
    189    }
    190    fclose(fileHandle);
    191  return content;
    192 }
    193 
    194 
    195 std::vector<char*>* Shader::fileReadArray(const std::string& fileName)
    196 {
    197   FILE*    stream;           //< The stream we use to read the file.
    198 
    199   if( (stream = fopen (fileName.c_str(), "rt")) == NULL)
    200   {
    201     PRINTF(1)("Shader could not open %s\n", fileName.c_str());
    202     return NULL;
    203   }
    204   std::vector<char*>* file = new std::vector<char*>;
    205 
    206   char lineBuffer[PARSELINELENGHT];
    207   char* addString;
    208   while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL)
    209   {
    210     addString = new char[strlen(lineBuffer)+1];
    211     strcpy(addString, lineBuffer);
    212     file->push_back(addString);
    213   }
    214   fclose(stream);
    215   return file;
     170bool Shader::readShader(const std::string& fileName, std::string& output)
     171{
     172  char lineBuffer[PARSELINELENGTH];
     173
     174  std::ifstream shader;
     175  shader.open(fileName.c_str());
     176  if (!shader.is_open())
     177    return false;
     178
     179
     180  while (!shader.eof())
     181  {
     182    shader.getline(lineBuffer, PARSELINELENGTH);
     183    output += lineBuffer;
     184    printf("line:: %s\n");
     185  }
     186
     187
     188  shader.close();
    216189}
    217190
  • branches/water/src/lib/graphics/shader.h

    r7818 r7822  
    4646
    4747
    48   char* fileRead(const std::string& fileName);
    49   std::vector<char*>* fileReadArray(const std::string& fileName);
     48  bool readShader(const std::string& fileName, std::string& output);
    5049
    5150
Note: See TracChangeset for help on using the changeset viewer.