SFML community forums
Help => General => Topic started by: Richy19 on November 21, 2011, 02:40:42 am
-
Runing make I get the following error:
/home/richy/Desktop/LaurentGomila-SFML-ac16c85/src/SFML/Network/Unix/SocketImpl.cpp:39:13: error: prototype for ‘sockaddr_in sf::priv::SocketImpl::CreateAddress(sf::Uint32, short unsigned int)’ does not match any in class ‘sf::priv::SocketImpl’
/home/richy/Desktop/LaurentGomila-SFML-ac16c85/src/SFML/Network/Unix/SocketImpl.hpp:68:24: error: candidate is: static sockaddr_in sf::priv::SocketImpl::CreateAddress(long unsigned int, short unsigned int)
make[2]: *** [src/SFML/Network/CMakeFiles/sfml-network.dir/Unix/SocketImpl.cpp.o] Error 1
make[1]: *** [src/SFML/Network/CMakeFiles/sfml-network.dir/all] Error 2
make: *** [all] Error 2
-
It's fixed.
Thanks for your feebdack.
-
Thought i would add to this instead of making a new thread, when I use dynamic linkng on linux i get:
error while loading shared libraries: libsfml-graphics-d.so.2: cannot open shared object file: No such file or directory
The only thing I have been able to do to fix it is to delete all the syslink librarie and rename the originals. Is there anything that can be done?
-
The libraries must be in a path the the libraries loader (ld) knows. You must configure it if it's not the case. Use ldconfig for permanent modifications, or the LD_LIBRARY_PATH environment variable for local changes.
-
I seem to be getting the same error I got a while back again, the window doesnt draw/redraw. This only happens on linux..
This time I ran valgrind to see if I can spot anything this is the log:
==30830== Memcheck, a memory error detector
==30830== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==30830== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==30830== Command: /home/richy/codeblocks/LoP/bin/Debug/LoP
==30830==
==30830== Invalid read of size 4
==30830== at 0x04c730f2: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== by 0x04b6796e: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== Address 0x484f3c8 is 0 bytes inside a block of size 1 alloc'd
==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467)
==30830== by 0x04c732be: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830==
==30830== Invalid write of size 4
==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04b86c5f: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== by 0x04b8717a: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== Address 0xb7855000 is not stack'd, malloc'd or (recently) free'd
==30830==
==30830== Syscall param writev(vector[...]) points to uninitialised byte(s)
==30830== at 0x04321d84: writev (writev.c:51)
==30830== by 0x00040004: ???
==30830== Address 0x6ec2f9c is 36 bytes inside a block of size 16,384 alloc'd
==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467)
==30830== by 0x04594551: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0)
==30830== by 0x041080d0: sf::priv::WindowImplX11::WindowImplX11(sf::VideoMode, std::string const&, unsigned long) (WindowImplX11.cpp:114)
==30830== by 0x04103524: sf::priv::WindowImpl::New(sf::VideoMode, std::string const&, unsigned int) (WindowImpl.cpp:60)
==30830==
==30830== Mismatched free() / delete / delete []
==30830== at 0x04027c02: free (vg_replace_malloc.c:366)
==30830== by 0x0458cb18: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0)
==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288)
==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94)
==30830== Address 0x8bae388 is 0 bytes inside a block of size 4,096 alloc'd
==30830== at 0x04027f65: operator
==30830== by 0x041089b6: sf::priv::WindowImplX11::SetIcon(unsigned int, unsigned int, unsigned char const*) (WindowImplX11.cpp:352)
==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288)
==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94)
==30830==
==30830== Invalid read of size 4
==30830== at 0x04cca9d4: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04cd5bba: _mesa_get_teximage (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04b84fe7: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== by 0x04cd6995: _mesa_GetnTexImageARB (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== Address 0xb7853000 is not stack'd, malloc'd or (recently) free'd
==30830==
==30830== Invalid write of size 4
==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so)
==30830== by 0x04b8555c: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== by 0x04b862ca: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so)
==30830== Address 0xb7852000 is not stack'd, malloc'd or (recently) free'd
==30830==
==30830== Conditional jump or move depends on uninitialised value(s)
==30830== at 0x04075609: sf::Renderer::SetShader(sf::Shader const*) (Renderer.cpp:255)
==30830== by 0x040770dc: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:83)
==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86)
==30830== by 0x0805d880: IGameStateManager::DrawSFML() (IGameStateManager.cpp:93)
==30830==
==30830== Conditional jump or move depends on uninitialised value(s)
==30830== at 0x0407510d: sf::Renderer::SetBlendMode(sf::Blend::Mode) (Renderer.cpp:190)
==30830== by 0x0405c965: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&)
==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86)
==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86)
==30830==
==30830== Conditional jump or move depends on uninitialised value(s)
==30830== at 0x040754e1: sf::Renderer::SetTexture(sf::Texture const*) (Renderer.cpp:236)
==30830== by 0x0407f289: sf::Sprite::Render(sf::RenderTarget&, sf::Renderer&)
==30830== by 0x0405c985: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&)
==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86)
==30830==
-
Have you tried the SFML examples first?
-
Appart from the shader exampple which gives a seg fault they all work fine.
just to check this is correctly setup right?
bool Engine::SetupOpenGL()
{
sf::ContextSettings Settings;
Settings.DepthBits = 24; // Request a 24 bits depth buffer
Settings.StencilBits = 8; // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = WindowSettings::AntiAliasing; // Request 2 levels of antialiasing
Settings.MajorVersion = 2;
Settings.MinorVersion = 1;
if(WindowSettings::FullScreen)
App.Create(sf::VideoMode(WindowSettings::WindowWidth, WindowSettings::WindowHeight, 32), "LOP", sf::Style::Fullscreen ,Settings);
else
App.Create(sf::VideoMode(WindowSettings::WindowWidth, WindowSettings::WindowHeight, 32), "LOP", sf::Style::Default ,Settings);
App.SetActive();
WindowSettings::WindowWidth = App.GetWidth();
WindowSettings::WindowHeight = App.GetHeight();
WindowSettings::AntiAliasing = App.GetSettings().AntialiasingLevel;
App.EnableVerticalSync(WindowSettings::VSync);
App.SetFramerateLimit(WindowSettings::FrameRateLimit);
App.ShowMouseCursor(false);
std::cout << "Using resolution: "<< App.GetWidth() << "x" << App.GetHeight() << std::endl;
App.SetIcon( LoPIcon.width, LoPIcon.height, LoPIcon.pixel_data );
try
{
std::cout << "Using OpenGL " << App.GetSettings().MajorVersion << "." << App.GetSettings().MinorVersion << std::endl;
if ((App.GetSettings().MajorVersion < Settings.MajorVersion) || (App.GetSettings().MajorVersion == Settings.MajorVersion && App.GetSettings().MinorVersion < Settings.MinorVersion))
{
std::cout << "Sorry but a minimum of OpenGL "<< Settings.MajorVersion <<"."<< Settings.MinorVersion <<" is required"<<std::endl;
std::cout << "Try updating your drivers." << std::endl;
return false;
}
}
catch(int e)
{
std::cout << "Failed to get OpenGL version. " << e << std::endl;
return false;
}
//*/
GLenum err = glewInit();
if (GLEW_OK != err)
{
// Problem: glewInit failed, something is seriously wrong.
std::cout << "Error: " << glewGetErrorString(err) << std::endl;
return false;
}
else
{
std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
}
std::cout << "Using an " << glGetString(GL_VENDOR) <<" graphics card."<< std::endl;
if(WindowSettings::AntiAliasing != App.GetSettings().AntialiasingLevel)
{
std::cout << "Antialiasing Level of " << WindowSettings::AntiAliasing << " was unavailable, using level " << App.GetSettings().AntialiasingLevel << " instead." << std::endl;
}
glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
// Cull triangles which normal is not towards the camera
glEnable(GL_CULL_FACE);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return true;
}
-
Yes. But this doesn't show the drawing.
You should write a complete and minimal code that reproduces your problem. We'll be able to spot the problem more easily.
-
Well I think this should work but it gives segmentation fault when building the shader.
Main.cpp
#include <iostream>
#include <sstream>
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "../codeblocks/Legend of Pedro/src/LoPIcon.h"
#include "3dSprite.hpp"
int main()
{
glm::mat4 orthoMatrix;
glm::mat4 perspectiveMatrix;
glm::mat4 cameraMatrix;
sf::RenderWindow App;
sf::ContextSettings Settings;
Settings.DepthBits = 24; // Request a 24 bits depth buffer
Settings.StencilBits = 8; // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = 8; // Request 2 levels of antialiasing
Settings.MajorVersion = 2;
Settings.MinorVersion = 1;
std::cout << "Building sprite" << std::endl;
d3Sprite hi;
if(false)//fullscreen
App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), "Legend Of Pedro", sf::Style::Fullscreen ,Settings);
else
App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), "Legend Of Pedro", sf::Style::Default ,Settings);
App.SetActive();
App.EnableVerticalSync(false);
App.SetFramerateLimit(0);
App.ShowMouseCursor(false);
std::cout << "Using resolution: "<< App.GetWidth() << "x" << App.GetHeight() << std::endl;
App.SetIcon( LoPIcon.width, LoPIcon.height, LoPIcon.pixel_data );
try
{
std::cout << "Using OpenGL " << App.GetSettings().MajorVersion << "." << App.GetSettings().MinorVersion << std::endl;
if ((App.GetSettings().MajorVersion < Settings.MajorVersion) || (App.GetSettings().MajorVersion == Settings.MajorVersion && App.GetSettings().MinorVersion < Settings.MinorVersion))
{
std::cout << "Sorry but a minimum of OpenGL "<< Settings.MajorVersion <<"."<< Settings.MinorVersion <<" is required"<<std::endl;
std::cout << "Try updating your drivers." << std::endl;
return false;
}
}
catch(int e)
{
std::cout << "Failed to get OpenGL version. " << e << std::endl;
return false;
}
//*/
GLenum err = glewInit();
if (GLEW_OK != err)
{
// Problem: glewInit failed, something is seriously wrong.
std::cout << "Error: " << glewGetErrorString(err) << std::endl;
return false;
}
else
{
std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
}
std::cout << "Using an " << glGetString(GL_VENDOR) <<" graphics card."<< std::endl;
if(8 != App.GetSettings().AntialiasingLevel)
{
std::cout << "Antialiasing Level of " << 8 << " was unavailable, using level " << App.GetSettings().AntialiasingLevel << " instead." << std::endl;
}
glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
// Cull triangles which normal is not towards the camera
glEnable(GL_CULL_FACE);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float width = App.GetWidth();
float height = App.GetHeight();
orthoMatrix = glm::ortho<float>(0.0f, width, height, 0.0f, 0.0f, 1.0f);
perspectiveMatrix = glm::perspective<float>(75, (width / height) ,0.1f,100.0f);
cameraMatrix = glm::lookAt(glm::vec3(0.0f, 3.0f, 5.0f), // Camera is here glm::vec3( 0, 0, 5 );
glm::vec3(0.0f), // and looks here : at the same position, plus "direction"
glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down)
);
hi.Initiate(&perspectiveMatrix, &cameraMatrix);
while(App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key pressed
//if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
// App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::F5))
App.Capture().SaveToFile("screenshot.png");
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
if(!App.IsOpened()) break;
hi.Update(App, true);
// Update(App.GetFrameTime()/1000.f);
App.SetActive();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
hi.Draw();
//if(gameStateManager->States()[gameStateManager->States().size() - 1] == m_GameState)
//Draw();
//else
//{
App.SaveGLStates();
// glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
std::stringstream ss;
ss << App.GetFrameTime();
ss << " ms";
sf::Text fps(ss.str(), sf::Font::GetDefaultFont(), 15);
fps.SetPosition(5.0f,5.0f);
App.Draw(fps);
App.RestoreGLStates();
// glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//}
App.Display();
}
}
Shader.hpp
#ifndef SHADER_HPP_INCLUDE
#define SHADER_HPP_INCLUDE
#pragma once
#include <GL/glew.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <glm/glm.hpp>
class Shader
{
GLuint VertexShaderID;
GLuint FragmentShaderID;
std::string FragmentShaderCode;
std::string VertexShaderCode;
public:
Shader();
Shader(const std::string &vertFileName, const std::string &fragFileName);
~Shader();
GLuint shaderID;
void LoadVertexShader(std::string &fileName);
void LoadFragmentShader(std::string &fileName);
void CompileVertexShader(GLint &Result, int &InfoLogLength);
void CompileFragmentShader(GLint &Result, int &InfoLogLength);
};
#endif //SHADER_HPP_INCLUDE
Shader.cpp
#include "Shader.hpp"
#include <glm/glm.hpp>
Shader::Shader() {}
Shader::Shader(const std::string &vertFileName, const std::string &fragFileName)
{
// Create the shaders
VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
// Read the Vertex Shader code from the file
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertFileName.c_str(), std::ios::in);
if(VertexShaderStream.is_open())
{
std::string Line = "";
while(getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}
// Read the Fragment Shader code from the file
std::string FragmentShaderCode;
std::ifstream FragmentShaderStream(fragFileName.c_str(), std::ios::in);
if(FragmentShaderStream.is_open())
{
std::string Line = "";
while(getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();
}
GLint Result = GL_FALSE;
int InfoLogLength;
// Compile Vertex Shader
printf("Compiling shader : %s\n", vertFileName.c_str());
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> VertexShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);
// Compile Fragment Shader
printf("Compiling shader : %s\n", fragFileName.c_str());
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
// Link the program
fprintf(stdout, "Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) );
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);
Shader::shaderID = ProgramID;
}
Shader::~Shader()
{
glDeleteProgram(shaderID);
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
}
void Shader::LoadVertexShader(std::string &fileName)
{
try
{
std::ifstream VertexShaderStream(fileName.c_str(), std::ios::in);
if(VertexShaderStream.is_open())
{
std::string Line = "";
while(getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}
}
catch(int e)
{
std::cout << "Failed to open Vertex shader, using basic shader." << std::endl << e << std::endl;
//VertexShaderCode =
}
}
void Shader::LoadFragmentShader(std::string &fileName)
{
try
{
std::ifstream FragmentShaderStream(fileName.c_str(), std::ios::in);
if(FragmentShaderStream.is_open())
{
std::string Line = "";
while(getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();
}
}
catch(int e)
{
std::cout << "Failed to open Frag shader, using basic shader." << std::endl << e << std::endl;
FragmentShaderCode = "void main(){ gl_FragColor = vec4(1,1,1,1); }";
}
}
void Shader::CompileVertexShader(GLint &Result, int &InfoLogLength)
{
// Compile Vertex Shader
std::cout << "Compiling Vertex Shader" << std::endl;
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> VertexShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
std::cout << &VertexShaderErrorMessage[0] << std::endl;
}
void Shader::CompileFragmentShader(GLint &Result, int &InfoLogLength)
{
// Compile Fragment Shader
std::cout << "Compiling Fragment Shader" << std::endl;
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
std::cout << &FragmentShaderErrorMessage[0] << std::endl;
}
LoPIcon.h
ifndef LOPICON_H_INCLUDED
#define LOPICON_H_INCLUDED
#pragma once
static const struct
{
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
unsigned char pixel_data[32 * 32 * 4 + 1];
} LoPIcon =
{
32, 32, 4,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\273\252|\0\273\252|\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\ ...",
};
#endif //LOPICON_H_INCLUDED
Drawable.hpp
#ifndef DRAWABLE_HPP_INCLUDE
#define DRAWABLE_HPP_INCLUDE
#pragma once
#include <glm/glm.hpp>
// glm::translate, glm::rotate, glm::scale
#include <glm/gtc/matrix_transform.hpp>
// glm::value_ptr
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
class Drawable
{
protected:
glm::mat4 *perspectiveMatrix;
glm::mat4 *cameraMatrix;
glm::mat4 MVP;
void printMat4x4(const glm::mat4 & mat);
public:
glm::mat4 modelMatrix;
Drawable();
virtual ~Drawable();
virtual void Initiate(glm::mat4 *persMat, glm::mat4 *camMat);
virtual void Update();
virtual void Draw();
};
#endif
#ifndef DRAWABLE_HPP_INCLUDE
#define DRAWABLE_HPP_INCLUDE
#pragma once
#include <glm/glm.hpp>
// glm::translate, glm::rotate, glm::scale
#include <glm/gtc/matrix_transform.hpp>
// glm::value_ptr
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
class Drawable
{
protected:
glm::mat4 *perspectiveMatrix;
glm::mat4 *cameraMatrix;
glm::mat4 MVP;
void printMat4x4(const glm::mat4 & mat);
public:
glm::mat4 modelMatrix;
Drawable();
virtual ~Drawable();
virtual void Initiate(glm::mat4 *persMat, glm::mat4 *camMat);
virtual void Update();
virtual void Draw();
};
#endif[/code]
Drawable.cpp
#include "Drawable.hpp"
Drawable::Drawable()
{
}
Drawable::~Drawable()
{
}
void Drawable::Initiate(glm::mat4 *persMat, glm::mat4 *camMat)
{
perspectiveMatrix = persMat;
cameraMatrix = camMat;
modelMatrix = glm::mat4(1.0f);
MVP = (*perspectiveMatrix) * (*cameraMatrix) * modelMatrix;
}
void Drawable::Update()
{
MVP = (*perspectiveMatrix) * (*cameraMatrix) * modelMatrix;
}
void Drawable::Draw()
{
}
void Drawable::printMat4x4(const glm::mat4 & mat)
{
std::cout << mat[0].x << "|" << mat[0].y << "|" << mat[0].z << "|" << mat[0].w << std::endl;
std::cout << mat[1].x << "|" << mat[1].y << "|" << mat[1].z << "|" << mat[1].w << std::endl;
std::cout << mat[2].x << "|" << mat[2].y << "|" << mat[2].z << "|" << mat[2].w << std::endl;
std::cout << mat[3].x << "|" << mat[3].y << "|" << mat[3].z << "|" << mat[3].w << std::endl;
}
Quad.hpp
#ifndef QUAD_HPP_INCLUDE
#define QUAD_HPP_INCLUDE
#pragma once
#include <GL/glew.h>
#include <glm/glm.hpp>
class Quad
{
protected:
GLfloat vertexList[3*6];
// This will identify our vertex buffer
GLuint vertexbuffer;
public:
Quad();
Quad(glm::vec3 *eVertexList);
~Quad();
void Initiate();
void Draw();
};
#endif
Quad.cpp
#include "Quad.hpp"
Quad::Quad()
{
vertexList[0] = 0.5f;
vertexList[1] = 1.0f;
vertexList[2] = 0.0f;
vertexList[3] = -0.5f;
vertexList[4] = 1.0f;
vertexList[5] = 0.0f;
vertexList[6] = -0.5f;
vertexList[7] = 0.0f;
vertexList[8] = 0.0f;
vertexList[9] = 0.5f;
vertexList[10] = 1.0f;
vertexList[11] = 0.0f;
vertexList[12] = -0.5f;
vertexList[13] = 0.0f;
vertexList[14] = 0.0f;
vertexList[15] = 0.5f;
vertexList[16] = 0.0f;
vertexList[17] = 0.0f;
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexList), vertexList, GL_STATIC_DRAW);
}
Quad::Quad(glm::vec3 *eVertexList)
{
vertexList[0] = eVertexList[0].x;
vertexList[1] = eVertexList[0].y;
vertexList[2] = eVertexList[0].z;
vertexList[3] = eVertexList[1].x;
vertexList[4] = eVertexList[1].y;
vertexList[5] = eVertexList[1].z;
vertexList[6] = eVertexList[2].x;
vertexList[7] = eVertexList[2].y;
vertexList[8] = eVertexList[2].z;
vertexList[9] = eVertexList[3].x;
vertexList[10] = eVertexList[3].y;
vertexList[11] = eVertexList[3].z;
vertexList[12] = eVertexList[4].x;
vertexList[13] = eVertexList[4].y;
vertexList[14] = eVertexList[4].z;
vertexList[15] = eVertexList[5].x;
vertexList[16] = eVertexList[5].y;
vertexList[17] = eVertexList[5].z;
}
Quad::~Quad()
{
}
void Quad::Initiate()
{
}
void Quad::Draw()
{
}
d3Sprite.hpp
#ifndef D3SPRITE_HPP_INCLUDED
#define D3SPRITE_HPP_INCLUDED
#pragma once
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <glm/glm.hpp>
// glm::translate, glm::rotate, glm::scale
#include <glm/gtc/matrix_transform.hpp>
// glm::value_ptr
#include <glm/gtc/type_ptr.hpp>
#include "./Drawable.hpp"
#include "../codeblocks/Legend of Pedro/src/Shader.hpp"
class d3Sprite : public Drawable
{
public:
d3Sprite(glm::vec3 pos = glm::vec3(0.0f));
~d3Sprite();
virtual void Initiate(glm::mat4 *persMat, glm::mat4 *camMat);
virtual void Update(sf::RenderWindow &App, bool blah = false);
virtual void Draw();
glm::vec3 position;
glm::vec3 rotation;
private:
GLuint MatrixID;
GLuint positionID;
GLuint UVID;
GLuint AlphaID;
GLfloat alphaAmount;
Shader shader;
GLfloat vertexList[3*6];
GLfloat UVList[6*2];
// This will identify our vertex buffer
GLuint vertexbuffer;
GLuint texturebuffer;
GLuint uvbuffer;
GLuint TextureID;
glm::vec3 mRotation;
glm::vec3 mPosition;
bool rotating;
};
#endif
d3Sprite.cpp
#include "./3dSprite.hpp"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <math.h>
d3Sprite::d3Sprite( glm::vec3 pos)
{
std::cout << "Building shader" << std::endl;
shader = Shader("./vert.vert" ,"./frag.frag");
std::cout << "Building img" << std::endl;
sf::Image img;
img.LoadFromFile("./pedro.png");
position = pos;
mPosition = glm::vec3(0.0f);
alphaAmount = 0.0f;
rotation = glm::vec3(0.0f);
mRotation = glm::vec3(0.0f);
rotating = false;
//img.FlipVertically();
UVList[0] = 1.0f;
UVList[1] = 0.0f;
UVList[2] = 0.0f;
UVList[3] = 0.0f;
UVList[4] = 0.0f;
UVList[5] = 1.0f;
UVList[6] = 1.0f;
UVList[7] = 0.0f;
UVList[8] = 0.0f;
UVList[9] = 1.0f;
UVList[10] = 1.0f;
UVList[11] = 1.0f;
vertexList[0] = 0.5f;
vertexList[1] = 1.0f;
vertexList[2] = 0.0f;
vertexList[3] = -0.5f;
vertexList[4] = 1.0f;
vertexList[5] = 0.0f;
vertexList[6] = -0.5f;
vertexList[7] = 0.0f;
vertexList[8] = 0.0f;
vertexList[9] = 0.5f;
vertexList[10] = 1.0f;
vertexList[11] = 0.0f;
vertexList[12] = -0.5f;
vertexList[13] = 0.0f;
vertexList[14] = 0.0f;
vertexList[15] = 0.5f;
vertexList[16] = 0.0f;
vertexList[17] = 0.0f;
std::cout << "Building buffers" << std::endl;
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexList), vertexList, GL_STATIC_DRAW);
MatrixID = glGetUniformLocation(shader.shaderID, "MVP");
AlphaID = glGetUniformLocation(shader.shaderID, "Alpha");
positionID = glGetAttribLocation(shader.shaderID, "Position");
TextureID = glGetUniformLocation(shader.shaderID, "myTexture");
UVID = glGetAttribLocation(shader.shaderID, "UV");
glGenBuffers(1, &uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(UVList), UVList, GL_STATIC_DRAW);
glGenTextures(1, &texturebuffer);
// "Bind" the newly created texture : all future texture functions will modify this texture
glBindTexture(GL_TEXTURE_2D, texturebuffer);
// Give the image to OpenGL
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, img.GetWidth(), img.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,img.GetPixelsPtr() );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
d3Sprite::~d3Sprite()
{
// Cleanup VBO and shader
glDeleteBuffers(1, &vertexbuffer);
glDeleteBuffers(1, &uvbuffer);
glDeleteTextures(1, &texturebuffer);
}
void d3Sprite::Initiate(glm::mat4 *persMat, glm::mat4 *camMat)
{
Drawable::Initiate(persMat, camMat);
}
void d3Sprite::Update(sf::RenderWindow &App, bool blah )
{
if(alphaAmount < 0.0f) alphaAmount = 0.0f;
if(alphaAmount > 1.0f) alphaAmount = 1.0f;
if(rotation.y > 1.0f)
{
rotating = true;
rotation.y -= 0.5f * App.GetFrameTime();
mRotation.y += 0.5f * App.GetFrameTime();
}
else if(rotation.y < -1.0f)
{
rotating = true;
rotation.y += 0.5f * App.GetFrameTime();
mRotation.y -= 0.5f * App.GetFrameTime();
}
else
{
mRotation.y += rotation.y;
rotation.y = 0.0f;
rotating = false;
}
if(rotating == false) mPosition = position;
else position = mPosition;
glm::mat4 modelTranslate = glm::translate( glm::mat4(1.0f), mPosition) ;
glm::mat4 modelRotate = glm::rotate( glm::mat4(1.0f), mRotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
modelMatrix = (modelTranslate * modelRotate) * modelRotate;
if(blah)
{
/*glm::mat4 camTranslate = glm::translate( modelTranslate , glm::vec3(0.0f, 3.0f, 5.0f) );
glm::mat4 lookAtCam = glm::lookAt(
glm::vec3(0.0f, 3.0f, 5.0f), // Camera is here glm::vec3( 0, 0, 5 );
glm::vec3(0.0f), // and looks here : at the same position, plus "direction"
glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down)
);
glm::mat4 camRotate = glm::rotate( glm::mat4(1.0f) , mRotation.y * -1, glm::vec3(0.0f, 1.0f, 0.0f));
engine->cameraMatrix = modelTranslate * lookAtCam * camRotate;// camRotate;// (camTranslate);
*/
if((((int)(mRotation.y / 90.0f)) % 2) == 0)
{
*cameraMatrix = glm::lookAt(
mPosition + glm::vec3(0.0f, 3.0f, 5.0f), // Camera is here glm::vec3( 0, 0, 5 );
mPosition, // and looks here : at the same position, plus "direction"
glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down)
);
}
else
{
*cameraMatrix = glm::lookAt(
mPosition + glm::vec3(0.0f, 3.0f, -5.0f), // Camera is here glm::vec3( 0, 0, 5 );
mPosition, // and looks here : at the same position, plus "direction"
glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down)
);
}
}
Drawable::Update();
modelMatrix = glm::mat4(1.0f);
}
void d3Sprite::Draw()
{
glUseProgram(shader.shaderID);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glUniform1f(AlphaID , alphaAmount);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texturebuffer);
glUniform1i(TextureID, 0);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(positionID);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
positionID, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer : UVs
glEnableVertexAttribArray(UVID);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glVertexAttribPointer(
UVID, // attribute. No particular reason for 1, but must match the layout in the shader.
2, // size : U+V => 2
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
// For each model you render, since the MVP will be different (at least the M part)
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 6); // Starting from vertex 0; 3 vertices total -> 1 triangle
glDisableVertexAttribArray(UVID);
glDisableVertexAttribArray(positionID);
}
-
http://www.sfml-dev.org/forum/viewtopic.php?p=36368#36368
-
Sorry will try to cut it down as much as possible.
-
I have notced some more problems when it comes to SFML2 and linux,
usiing the following code:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Texture tex;
tex.LoadFromFile("ship.png");
sf::Sprite spr = sf::Sprite(tex);
sf::Shader bloom;
bloom.LoadFromFile("Bloom.fx");
bloom.SetParameter("amount", 0.6f);
bloom.SetParameter("blurSize", 0.5f / 800);
sf::RenderTexture bloomImage;
bloomImage.Create(800,600);
sf::Sprite bloomSprite = sf::Sprite(bloomImage.GetTexture());
while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event)) if (Event.Type == sf::Event::Closed) App.Close();
App.Clear();
bloomImage.Clear(sf::Color(0.f,0.f,0.f,0.f));
bloomImage.Draw(spr, bloom);
bloom.SetParameter("horizontal", 0);
bloomImage.Display();
App.Draw(bloomSprite, bloom);
bloom.SetParameter("horizontal", 1);
App.Display();
}
return 0;
}
and shader
#version 120
uniform float blurSize;
uniform float amount;
uniform sampler2D texture;
uniform float horizontal;
void main()
{
vec4 sum = vec4(0.0);
float gaussian[17] = float[17] (0.148, 0.145, 0.136, 0.123, 0.107, 0.090, 0.072, 0.055, 0.041, 0.029, 0.020, 0.013, 0.008, 0.005, 0.003, 0.002, 0.001);
int length = gaussian.length();
for (int i = -length + 1; i < length; i++)
{
vec2 coords = vec2(gl_TexCoord[0].x - i * blurSize, gl_TexCoord[0].y);
if (horizontal == 0)
coords = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y - i * blurSize);
sum += texture2D(texture, coords) * gaussian[int(abs(i))] * 0.5;
}
float avg = dot(sum.rgb, vec3(0.299, 0.587, 0.114));
sum = vec4(avg, avg, avg, 1);
vec4 col = (sum * sum * amount) + texture2D(texture, gl_TexCoord[0].xy);
gl_FragColor = col;
}
It exits with error code 1, when i use gdb to debug and set a break point at exit I got this:
Reading symbols from /home/richy/codeblocks/anoy/bin/Debug/anoy...done.
(gdb) b exit
Function "exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (exit) pending.
(gdb) b _exit
Function "_exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (_exit) pending.
(gdb) b exit()
Function "exit()" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 3 (exit()) pending.
(gdb) run
Starting program: /home/richy/codeblocks/anoy/bin/Debug/anoy
[Thread debugging using libthread_db enabled]
Breakpoint 1, __GI_exit (status=1) at exit.c:99
99 exit.c: No such file or directory.
in exit.c
(gdb) bt
#0 __GI_exit (status=1) at exit.c:99
#1 0x00855697 in _intel_batchbuffer_flush ()
from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#2 0x008594f0 in intel_flush () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#3 0x00859532 in ?? () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#4 0x009354b0 in _mesa_flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#5 0x00935bce in _mesa_Flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#6 0x00167ac1 in sf::priv::RenderTextureImplFBO::UpdateTexture (
this=0x8b5cc50)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTextureImplFBO.cpp:140
#7 0x001670e0 in sf::RenderTexture::Display (this=0xbfffdb00)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTexture.cpp:115
#8 0x080494e0 in main () at /home/richy/codeblocks/anoy/main.cpp:40
(gdb)
Also in linux I have noticed that unless you load textures once the current window has been created they are broken, however in windows you can load textures at any time and the images will be fine. not sure if this is meant to happen or what