Jump to content

  • Log In with Google      Sign In   
  • Create Account


santa01

Member Since 16 May 2012
Offline Last Active Oct 25 2013 02:00 AM

#5029467 SDL + OpenGL V-Sync

Posted by santa01 on 06 February 2013 - 11:49 AM

Do you suggest using SDL 1.3.0?

 

It will be a good start smile.png As proanim@ mentioned its now 2.0 and should be cloned/compiled from mercurial repo.




#5029367 SDL + OpenGL V-Sync

Posted by santa01 on 06 February 2013 - 06:17 AM

glXSwapIntervalEXT is not crossplatform, for win you should call wglSwapIntervalEXT. Also, if I am not mistaken, for glXSwapIntervalEXT you should link against libX11 as -lX11

 

Also you can look at this post: http://forums.libsdl.org/viewtopic.php?p=24220&sid=a85c51359b9040234fece5114e1d5787#24220




#5015389 Linux: send signal to stop process

Posted by santa01 on 29 December 2012 - 04:44 AM

kill(getpid(), SIGTERM);

I'd suggest also to install a handler for this signal to perform any manual cleanups like finishing network sessions properly, dump config files etc.




#5015039 Good books for OpenGL

Posted by santa01 on 28 December 2012 - 04:47 AM

I haven't found any OpenGL gamedev books for OpenGL3 or higher. I guess its worth sticking to OpenGL3/4 tutorials over the net + look throught some `generic gamedev books' which would give you an insight into the basic math.




#5014845 X11: Locking cursor in the center of the window

Posted by santa01 on 27 December 2012 - 02:44 PM

I don't think there is a function to lock the cursor in position (shame on me if I'm wrong), but you can call XWarpPointer every time you receive a mouse event, which has the same effect.

sorry for plusing your answer smile.png its not exactly the way its done. XWarpPointer() would move the cursor and produce the mouse event itself, performance falls drastically for no good reason. its better to call XWarpPointer() after the event queue is empty:

while (XPending(display)) {
    XNextEvent(display, &event);
    // process you events
}

XWarpPointer(...);

or you can look through the freeglut sources to find out how its implemented for X11.




#5014841 Why is it "bad" to call srand multiple times?

Posted by santa01 on 27 December 2012 - 02:36 PM

I keep reading this, but never an explanation. Being curious, I took a look at Visual Studio's code for rand and srand and all srand does is set a global variable. rand performs a typical pseudo-random number algorithm based on the global variable.

 

because you just don't need to do that, its like checking variable twice just to make sure its value is consistent. just do

// time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
srand(time()); // well not sure time() is present in MSVC



#5014549 How to write a good function printing float matrix to console?

Posted by santa01 on 26 December 2012 - 06:16 PM

If you want to make your output function have a flexible choice of destination, you can make it take a std::ostream & argument for destination. Then whoever uses it can dump it to a std::stringstream, std::cout or a std::fstream. One option is to just overload std::ostream & operator<<(std::ostream &, const YourClass &) so you can use the formatted output operator.

 

This. And for requirement (1) I'd wrap the sprintf() call to make a fancy formatting (sorry for non C++ approach, but I don't know any decent STL classes to solve this issue).




#5014547 how to avoid macro loops

Posted by santa01 on 26 December 2012 - 06:10 PM

Why do you guys load shader sources line by line? Thats a extra runtime. Shader sources aren't very big, everything can be done with one read:

GLuint ShaderLoader::shaderFromFile(const std::string& name, GLenum type) {
    std::fstream file(name.c_str(), std::ios::binary | std::ios::in);
    if (!file.good()) {
        Logger::getInstance().log(Logger::LOG_ERROR, "Cannot open file %s", name.c_str());
        return 0;
    }

    file.seekg(0, std::ios::end);
    int sourceLength = file.tellg();
    GLchar* shaderSource = new GLchar[sourceLength + 1];

    file.seekg(0, std::ios::beg);
    file.read(shaderSource, sourceLength);
    shaderSource[sourceLength] = 0;

    GLuint shader = glCreateShader(type);
    glShaderSource(shader, 1, (const GLchar**)&shaderSource, NULL);
    glCompileShader(shader);

    delete[] shaderSource;

    GLint compileStatus;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
    if (compileStatus == GL_FALSE) {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        GLchar* infoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, infoLog);
        
        Logger::getInstance().log(Logger::LOG_ERROR, "In file %s: %s", name.c_str(), infoLog);
        delete[] infoLog;
    }
    
    return shader;
}



#5014540 minimize glDrawElements or glBindBuffer...?

Posted by santa01 on 26 December 2012 - 05:52 PM

OpenGL standard doesn't describe how VBO binding should be implemented internally, I guess this would be vendor specific, whereas reducing draw calls would give you an average performance boost.




#4973253 Camera pointing to -Z

Posted by santa01 on 25 August 2012 - 09:03 AM

Ok, as far as I understand when camera is pointing -Z direction its actually shows whats behind it, right? `Looking directions' is also reversed. Does that mean the OpenGL depth test parameters should be like:
glDepthFunc(GL_GEQUAL);
glClearDepth(0.0f);
?


PARTNERS