Skip to content

Commit

Permalink
Preparing for 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo committed Nov 25, 2017
1 parent 4b5ac52 commit 60e5f0b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ glslViewer test.frag
vim test.frag
```

**Note**: In RaspberryPi you can avoid taking over the screen by using the `-l` or `--live-coding` flags so you can see the console. Also you can edit the shader file through ssh/sftp.
**Note**: In RaspberryPi you can avoid taking over the screen by using the `-l` flags so you can see the console. Also you can edit the shader file through ssh/sftp.

**Note**: On Linux and MacOS you may used to edit your shaders with Sublime Text 2, if thats your case you should try this [Sublime Text 2 plugin that lunch glslViewer every time you open a shader](https://packagecontrol.io/packages/glslViewer).

Expand Down Expand Up @@ -225,7 +225,9 @@ Beside for texture uniforms other arguments can be add to `glslViewer`:

* `-o [image.png]` save the viewport to a image file before

* `-l` or `--live-coding` to draw a 500x500 billboard on the top right corner of the screen that let you see the code and the shader at the same time. (RaspberryPi only)
* `-l` to draw a 500x500 billboard on the top right corner of the screen that let you see the code and the shader at the same time. (RaspberryPi only)

* `-c`or `--cursor` show cursor.

* `--headless` headless rendering. Very usefull for making images or benchmarking.

Expand All @@ -237,6 +239,8 @@ Beside for texture uniforms other arguments can be add to `glslViewer`:

* `-vFlip` all textures after will be fliped vertically

* `-v` verbose outputs

* `--help` display the available command line options

### Inject other files
Expand Down
2 changes: 1 addition & 1 deletion src/gl/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void Shader::setUniform(const std::string& _name, const float *_array, unsigned
glUniform4f(loc, _array[0], _array[1], _array[2], _array[2]);
}
else {
std::cout << "Passing matrix uniform as array, not supported yet" << std::endl;
std::cerr << "Passing matrix uniform as array, not supported yet" << std::endl;
}
}
}
Expand Down
46 changes: 25 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const std::string* fragPath = nullptr;
int iVert = -1;
std::string vertSource = "";
const std::string* vertPath = nullptr;
bool verbose = false;

// CAMERA
Camera cam;
Expand Down Expand Up @@ -141,7 +142,7 @@ int main(int argc, char **argv){
windowPosAndSize.z = toInt(std::string(argv[i]));
}
else if ( std::string(argv[i]) == "-h" ||
std::string(argv[i]) == "--height") {
std::string(argv[i]) == "--height" ) {
i++;
windowPosAndSize.w = toInt(std::string(argv[i]));
}
Expand Down Expand Up @@ -197,28 +198,31 @@ int main(int argc, char **argv){
argument == "-h" || argument == "--height" ) {
i++;
}
else if (argument == "--headless") {
else if (argument == "-l" ||
argument == "--headless") {
}
else if (argument == "-l") {
else if ( argument == "-v" ||
argument == "--verbose" ) {
verbose = true;
}
else if (argument == "-m") {
else if (argument == "-c" || argument == "--cursor") {
cursor.init();
}
else if (argument == "-s" || argument == "--sec") {
i++;
argument = std::string(argv[i]);
timeLimit = toFloat(argument);
std::cout << "Will exit in " << timeLimit << " seconds." << std::endl;
std::cout << "// Will exit in " << timeLimit << " seconds." << std::endl;
}
else if (argument == "-o") {
i++;
argument = std::string(argv[i]);
if (haveExt(argument, "png")) {
outputFile = argument;
std::cout << "Will save screenshot to " << outputFile << " on exit." << std::endl;
std::cout << "// Will save screenshot to " << outputFile << " on exit." << std::endl;
}
else {
std::cout << "At the moment screenshots only support PNG formats" << std::endl;
std::cerr << "At the moment screenshots only support PNG formats" << std::endl;
}
}
else if (iFrag == -1 && (haveExt(argument,"frag") || haveExt(argument,"fs"))) {
Expand Down Expand Up @@ -284,9 +288,9 @@ int main(int argc, char **argv){
file.vFlip = vFlip;
files.push_back(file);

std::cout << "Loading " << argument << " as the following uniform: " << std::endl;
std::cout << " uniform sampler2D " << name << "; // loaded"<< std::endl;
std::cout << " uniform vec2 " << name << "Resolution;"<< std::endl;
std::cout << "// Loading " << argument << " as the following uniform: " << std::endl;
std::cout << "// uniform sampler2D " << name << "; // loaded"<< std::endl;
std::cout << "// uniform vec2 " << name << "Resolution;"<< std::endl;
textureCounter++;
}
}
Expand Down Expand Up @@ -318,9 +322,9 @@ int main(int argc, char **argv){
file.vFlip = vFlip;
files.push_back(file);

std::cout << "Loading " << argument << " as the following uniform: " << std::endl;
std::cout << " uniform sampler2D " << parameterPair << "; // loaded"<< std::endl;
std::cout << " uniform vec2 " << parameterPair << "Resolution;"<< std::endl;
std::cout << "// Loading " << argument << " as the following uniform: " << std::endl;
std::cout << "// uniform sampler2D " << parameterPair << "; // loaded"<< std::endl;
std::cout << "// uniform vec2 " << parameterPair << "Resolution;"<< std::endl;
}
}
}
Expand Down Expand Up @@ -417,15 +421,15 @@ void cinWatcherThread() {
}
else if (line == "fps") {
// std::cout << getFPS() << std::endl;
printf("%f\n",getFPS());
printf("%f\n", getFPS());
}
else if (line == "delta") {
// std::cout << getDelta() << std::endl;
printf("%f\n",getDelta());
printf("%f\n", getDelta());
}
else if (line == "time") {
// std::cout << getTime() << std::endl;
printf("%f\n",getTime());
printf("%f\n", getTime());
}
else if (line == "date") {
glm::vec4 date = getDate();
Expand Down Expand Up @@ -544,7 +548,7 @@ void setup() {
vertSource = vbo->getVertexLayout()->getDefaultVertShader();
}

shader.load(fragSource, vertSource, defines, true);
shader.load(fragSource, vertSource, defines, verbose);

cam.setViewport(getWindowWidth(), getWindowHeight());
cam.setPosition(glm::vec3(0.0,0.0,-3.));
Expand Down Expand Up @@ -679,14 +683,14 @@ void onFileChange(int index) {
fragSource = "";
if (loadFromPath(path, &fragSource, include_folders)) {
shader.detach(GL_FRAGMENT_SHADER | GL_VERTEX_SHADER);
shader.load(fragSource, vertSource, defines, true);
shader.load(fragSource, vertSource, defines, verbose);
}
}
else if (type == "vertex") {
vertSource = "";
if (loadFromPath(path, &vertSource, include_folders)) {
shader.detach(GL_FRAGMENT_SHADER | GL_VERTEX_SHADER);
shader.load(fragSource, vertSource, defines, true);
shader.load(fragSource, vertSource, defines, verbose);
}
}
else if (type == "geometry") {
Expand Down Expand Up @@ -804,7 +808,7 @@ void screenshot(std::string _file) {
unsigned char* pixels = new unsigned char[getWindowWidth()*getWindowHeight()*4];
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Texture::savePixels(_file, pixels, getWindowWidth(), getWindowHeight());
std::cout << "Screenshot saved to " << _file << std::endl;
std::cout << "// Screenshot saved to " << _file << std::endl;
}
}

Expand All @@ -828,5 +832,5 @@ void onExit() {
}

void printUsage(char * executableName) {
std::cerr << "Usage: " << executableName << " shader.frag [shader.vert] [mesh.(obj/.ply)] [texture.(png/jpg)] [-textureNameA texture.(png/jpg)] [-u] [-x x] [-y y] [-w width] [-h height] [-l/--livecoding] [--square] [-s seconds] [-o screenshot.png] [--help]\n";
std::cerr << "Usage: " << executableName << " <shader>.frag [<shader>.vert] [<mesh>.(obj/.ply)] [<texture>.(png/jpg)] [-<uniformName> <texture>.(png/jpg)] [-vFlip] [-x <x>] [-y <y>] [-w <width>] [-h <height>] [-l] [--square] [-s/--sec <seconds>] [-o <screenshot_file>.png] [--headless] [-c/--cursor] [-I<include_folder>] [-D<define>] [-v/--verbose] [--help]\n";
}

0 comments on commit 60e5f0b

Please sign in to comment.