• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
proanim

how to avoid macro loops

32 posts in this topic

When I get to delete[] shaderSource; line
vertex shader is the same as i posted and fragment shader doesn't have extra symbols at the end huh.png Edited by proanim
0

Share this post


Link to post
Share on other sites

Can you confirm that when source is explicitly defined in code lie this:

    const GLchar* shaderSource = "#version 330\n"
        "layout (location = 0) in vec3 inPosition;\n"
        "layout (location = 1) in vec3 inColor;\n"
        "smooth out vec3 theColor;\n"
        "void main()\n"
        "{\n"
            "gl_Position = vec4(inPosition, 1.0);\n"
            "theColor = inColor;\n"
        "}\n"

    glShaderSource(uiShader, 1, &shaderSource, NULL);
    glCompileShader(uiShader);

    // dont call delete[] on const arrays, you will get SIGSEGV

    GLint compileStatus;
    glGetShaderiv(uiShader, GL_COMPILE_STATUS, &compileStatus);

    if (compileStatus == GL_FALSE) {
        GLint infoLogLength;
        glGetShaderiv(uiShader, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        GLchar* infoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(uiShader, infoLogLength, NULL, infoLog);
        
		ofstream outfile;
		outfile.open ("log.txt");
		outfile << infoLog << endl;
		outfile.close();

        delete[] infoLog;
    }

it compiles without errors?

Edited by santa01
0

Share this post


Link to post
Share on other sites

It compiles without errors but it doesn't have any effect. I tried your way, there was no effect from the shader but the debugger did show correct output from shaderSource. I also tried to use it this way

 

bool CShader::loadVertexShader(int a_iType)
{
	const GLchar* shaderSource = "#version 330\n"
        "layout (location = 0) in vec3 inPosition;\n"
        "layout (location = 1) in vec3 inColor;\n"
        "smooth out vec3 theColor;\n"
        "void main()\n"
        "{\n"
            "gl_Position = vec4(inPosition, 1.0);\n"
            "theColor = inColor;\n"
        "}\n";

	uiShader = glCreateShader(a_iType);
    glShaderSource(uiShader, 1, &shaderSource, NULL);
    glCompileShader(uiShader);

	ofstream outfile;
	outfile.open ("log.txt", fstream::out | fstream::app);
	outfile << shaderSource << endl;
	outfile << endl;
	outfile.close();

	GLint compileStatus;
    glGetShaderiv(uiShader, GL_COMPILE_STATUS, &compileStatus);
 
    if (compileStatus == GL_FALSE)
	{
        GLint infoLogLength;
        glGetShaderiv(uiShader, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        GLchar* infoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(uiShader, infoLogLength, NULL, infoLog);
        
		ofstream outfile;
		outfile.open ("log.txt");
		outfile << infoLog << endl;
		outfile.close();
 
        delete[] infoLog;
    }

	return 1;
}

 

also no effect. I did this just in case I don't miss anything when doing this part

 

// Load shaders and create shader program
//shVertex.loadShader("data/shaders/color.vert", GL_VERTEX_SHADER);
shVertex.loadVertexShader(GL_VERTEX_SHADER);
shFragment.loadShader("data/shaders/color.frag", GL_FRAGMENT_SHADER);
0

Share this post


Link to post
Share on other sites

What do you mean by "no effect?" If things aren't drawing/showing, it possible your draw calls and/or vertex data are incorrect.

0

Share this post


Link to post
Share on other sites

[quote name='proanim' timestamp='1356714928' post='5015107']
also no effect.
[/quote]

We are currently talking about these compilation errors:

Fragment shader failed to compile with the following errors:
ERROR: 2:1: error(#307) Profile "smooth" is not supported
ERROR: 2:1: error(#76) Syntax error: unexpected tokens following #version
ERROR: error(#273) 2 compilation errors.  No code generated

right?

 

If yes, then glsl compiler definitely considers shader source as a one line like:

 

#version 330layout (location = 0) in vec3 inPosition;layout (location = 1) in vec3 inColor;smooth out vec3 theColor;

 

which isn't legal and the only stuff I can suggest here is to try out windows EOL sequence of \r\n instead of pure \n in a shaderSource above

 

If no, than please provide something more valuable rather than `also no effect', glsl compilation log at least (if nothing is printed and nothing is rendered than its worth printing shader compilation status log with out the check `if (compileStatus == GL_FALSE)')

0

Share this post


Link to post
Share on other sites

Well this is only simple trinagle on the screen that should make use of color shader. The works by default, and somewhere on the half of this topic there was a solution that improved my original shader loading function (and it works no problem). But then since it was suggested not to read the file line by line and do extra work after, I would like to try and make that work.

And this approach gives white triangle instead of rainbow color effect that you see in usual tutorials that use color shader. That is what i mean by having 'no effect'. As far as I can tell there is no errors in the function or in shaders, this problem is very wierd to me since even if I supply vertex shader which I am having problems (like const GLchar* from above) with for whatever reason, it doesn't work.

0

Share this post


Link to post
Share on other sites

[quote name='proanim' timestamp='1356721348' post='5015133']
And this approach gives white triangle instead of rainbow color effect that you see in usual tutorials that use color shader.
[/quote]

How do you render your polygon?

0

Share this post


Link to post
Share on other sites
As the others have mentioned, you really have (at least) two distinct problems here. The first is loading the file contents into memory, and the second relates to loading and applying shaders. You should approach these as different problems, and solve and test them in isolation.

As others have demonstrated, use a hard coded string literal to test your shader code.

Likewise, write a small program to demonstrate and test file loading. For example, you can load a file into a string fairly simply using streambuf iterators:
#include <string>
#include <iterator>
#include <fstream>
#include <iostream>

std::string read(std::istream &stream) {
    std::istreambuf_iterator<char> begin(stream);
    std::istreambuf_iterator<char> end;
    return std::string(begin, end);
}

int main() {
    std::ifstream in("ReadMe.txt");
    if(in) {
         std::string data = read(in);
         std::cout << "The file contents are:\n";
         std::cout << data;
    } else {
        std::cerr << "Failed to open the file" << std::endl;
        return 1;

    }
}
It is also possible to make read() a one liner, but it falls afoul of the most vexing parse.

Once you've verified that you can load strings correctly, and that you can create and use shaders correctly, then is the time to create a program that does both. Breaking a complex task into simpler sub-tasks is called "divide and conquer" and is absolutely necessary for writing functioning and maintainable software. Edited by rip-off
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0