1. Post #1321
    Gold Member
    GamingRobot32's Avatar
    January 2012
    155 Posts
    (In C#) How do I create a menu in which I can choose between different options?


    ^like that
    You might look at the RadioCheck property
    http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  2. Post #1322
    Gold Member
    Mr_Razzums's Avatar
    December 2005
    4,571 Posts
    Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors.


    I need to check to see if a cord(x, y) is within the diamond in the square.

    in this function

    Code:
            private bool IsoLogic(Rectangle dimension, Vector2 sp)
            {
                Vector2 start = new Vector2(dimension.X, dimension.Y);
    
                if (sp.X > start.X && sp.Y > start.Y)
                {
                    if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left
                    {
                        return true;
                    }
                    if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right
                    {
                        return true;
                    }
                    if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32))  //check bottom left
                    {
                        return true;
                    }
                    if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right
                    {
                        return true;
                    }
                }
                return false;
           }
    This is the closest I've gotten, but it still doesn't work correctly.
    Vector2 start gets the upper left corner of the square.

    Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  3. Post #1323
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    Time to ask for help at Facepunch too I guess. I'm trying to add physics to my 3D game engine however the mesh is ending up horribly mis-aligned.




    I'm using Jitter since it seems quite nice and it doesn't want to do everything for you. I'm trying to build a compound shape of convex hulls, one for each mesh in the model. Currently however the different hulls are being transformed incorrectly, resulting in a misaligned mesh.

    http://pastebin.com/PNkWVfsz is my current physics entity class. Any help is much appreciated.
    How do you define the origin of your models? IIRC Jitter adjusts the origin of rigid bodies to their center of mass.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  4. Post #1324
    Gold Member
    ThePuska's Avatar
    October 2005
    3,440 Posts
    Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors.


    I need to check to see if a cord(x, y) is within the diamond in the square.

    in this function

    Code:
            private bool IsoLogic(Rectangle dimension, Vector2 sp)
            {
                Vector2 start = new Vector2(dimension.X, dimension.Y);
    
                if (sp.X > start.X && sp.Y > start.Y)
                {
                    if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left
                    {
                        return true;
                    }
                    if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right
                    {
                        return true;
                    }
                    if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32))  //check bottom left
                    {
                        return true;
                    }
                    if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right
                    {
                        return true;
                    }
                }
                return false;
           }
    This is the closest I've gotten, but it still doesn't work correctly.
    Vector2 start gets the upper left corner of the square.

    Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.
    ratio = 64.0 / 32.0; // ratio of x/y
    maxdist = 32.0;
    
    dx = (center.x - pos.x);
    dy = (center.y - pos.y) * ratio;
    
    d = abs(dx) + abs(dy);
    
    return (d <= maxdist);

    The metric to get "circles" that look like diamonds is , and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation.

    Edited:

    Don't worry if that doesn't make any sense
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  5. Post #1325
    Silverboarder's Avatar
    April 2009
    26 Posts
    I want to make a board game using Java. (to learn it better)
    I am a beginner and i was wondering what imports to use and if anyone could point me in the right direction with where to start.
    Also tutorials that i should definitely read for this.

    I have an image with the board itself.
    Things what i want to be able to do:
    - i want to be able to specify the amount of players and then have that amount of pawns.
    - a dice
    - drag and drop the pawns
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events

  6. Post #1326

    April 2012
    56 Posts
    @Silverboarder

    The real Drag & Drop interface works easy with components, but as you just
    wish to DND with some own images within the scope of your own program
    (and just within one JComponent) you can skip DND interface this and just
    use the mouse listener for this.

    For the easy way (just mouse listener) you just need minimal knowledge of swing.
    You only want an initial frame asking how many players (possible board+pawn images)
    and reuse this frame to add the a panel as canvas for the drawing.

    More interesting is the Graphis2D interface, you will use it for drawing your images.
    But in most simple case you will only use the drawImage.
    Just make a subclass of JPanel and overwrite the paint. From here you can use the
    Graphics2D interface. Add the mouse listener (to either frame or panel) and you're
    almost done ;)

    It becomes more complicated if you actually want to add game-logic etc.

    Marco
    Reply With Quote Edit / Delete Windows Vista Germany Show Events

  7. Post #1327
    Richy19's Avatar
    May 2010
    5,408 Posts
    Can anyone see anything in my shader class that would cause a segfault?

    
    #ifndef sSHADER_HPP_INCLUDE
    #define sSHADER_HPP_INCLUDE
    #pragma once
    
    #include <string>
    #include <map>
    #include <vector>
    #include <GL/glew.h>
    
    class Shader
    {
    protected:
        GLuint VertexShaderID;
        GLuint FragmentShaderID;
        std::string FragmentShaderCode;
        std::string VertexShaderCode;
        GLuint shaderID;
        void LoadVertexShader(std::string &fileName);
        void LoadFragmentShader(std::string &fileName);
        void CompileVertexShader(GLint &Result, int &InfoLogLength);
        void CompileFragmentShader(GLint &Result, int &InfoLogLength);
        std::map< std::string, GLuint > UniformVariableIDList;
        std::map< std::string, GLuint > AttributeVariableIDList;
    public:
    
        ///
        /// \brief Empty constructor
        ///
        Shader();
    
        ///
        /// \brief Construct shader with given files
        /// \param Vertex shader filename
        /// \param Fragment shader filename
        ///
        Shader(const std::string &vertFileName, const std::string &fragFileName);
    
        ///
        /// \brief Deconstructor
        ///
        ~Shader();
    
        ///
        /// \brief Retreive the shaders ID
        ///
        GLuint GetShaderID();
    
        ///
        /// \brief Bind the shader for use
        ///
        void Bind();
    
        ///
        /// \brief Deactivate all shaders
        ///
        static void Unbind();
    
        ///
        /// \brief Get the ID of a given attribute
        /// \param Attribute name
        ///
        GLuint GetAttribute(const std::string attName);
    
        ///
        /// \brief Get the ID of a given uniform
        /// \param Uniform name
        ///
        GLuint GetUniform(const std::string uniName);
    };
    
    
    #endif //SHADER_HPP_INCLUDE
    

    
    #include <iostream>
    #include <fstream>
    #include <GL/glew.h>
    #include <glm/glm.hpp>
    
    #include "Shader.hpp"
    
    
    Shader::Shader() {}
    
    Shader::Shader(const std::string &vertFileName, const std::string &fragFileName)
    {
        AttributeVariableIDList.clear();
        UniformVariableIDList.clear();
    
        /// 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 ", 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 ", 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 ");
        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;
    
    }
    
    GLuint Shader::GetShaderID()
    {
        return shaderID;
    }
    
    void Shader::Bind()
    {
        glUseProgram(shaderID);
    }
    
    void Shader::Unbind()
    {
        glUseProgram(0);
    }
    
    GLuint Shader::GetAttribute(std::string attName)
    {
        std::map<std::string, GLuint>::iterator it = AttributeVariableIDList.find(attName);
        if (it != AttributeVariableIDList.end())
        {
            return it->second;
        }
    
        GLuint attribute = glGetAttribLocation(shaderID, attName.c_str());
        AttributeVariableIDList[attName] = attribute;
    }
    
    GLuint Shader::GetUniform(std::string uniName)
    {
        std::map<std::string, GLuint>::iterator it = UniformVariableIDList.find(uniName);
        if (it != UniformVariableIDList.end())
        {
            return it->second;
        }
    
        GLuint uniform = glGetAttribLocation(shaderID, uniName.c_str());
        UniformVariableIDList[uniName] = uniform;
    
    }
    
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Dumb Dumb x 1 (list)

  8. Post #1328
    Gold Member
    Mr_Razzums's Avatar
    December 2005
    4,571 Posts
    ratio = 64.0 / 32.0; // ratio of x/y
    maxdist = 32.0;
    
    dx = (center.x - pos.x);
    dy = (center.y - pos.y) * ratio;
    
    d = abs(dx) + abs(dy);
    
    return (d <= maxdist);

    The metric to get "circles" that look like diamonds is , and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation.

    Edited:

    Don't worry if that doesn't make any sense

    Heh well its alright I got it now... Took me way too long to make this algorithm...

    Code:
                float min;
                float high;
    
                if (sp.X > start.X && sp.Y > start.Y && (sp.X < start.X + 64 && sp.Y < start.Y + 32))
                {
                    if (nc.X < 32)
                    {
                        min = 16 - (nc.X / 2);
                        high = (nc.X / 2) + 16;
    
                        if (nc.Y > min  && nc.Y < high)
                            return true;
                    }
                    else if (nc.X >= 32)
                    {
                        min = (nc.X / 2) - 16;
                        high = 32 - min;
    
                        if (nc.Y > min && nc.Y < high)
                            return true;
                    }
                }
                return false;
    Math is my weakness... and it really shows in my programming :/
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  9. Post #1329
    kill yourself
    Protocol7's Avatar
    June 2006
    26,080 Posts
    Can anyone see anything in my shader class that would cause a segfault?

    [code]
    use a debugger

    set a breakpoint

    and find out yourself

    seriously that should be in the OP - "set a breakpoint and step through your code"
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 2 (list)

  10. Post #1330
    Richy19's Avatar
    May 2010
    5,408 Posts
    use a debugger

    set a breakpoint

    and find out yourself

    seriously that should be in the OP - "set a breakpoint and step through your code"
    This is what my debbuger gives me:
    Code:
    valgrind ./FPSd
    ==2350== Memcheck, a memory error detector
    ==2350== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    ==2350== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
    ==2350== Command: ./FPSd
    ==2350== 
    ==2350== Jump to the invalid address stated on the next line
    ==2350==    at 0x0: ???
    ==2350==    by 0x804D4CF: Block::Block() (Block.cpp:4)
    ==2350==    by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6)
    ==2350==    by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18)
    ==2350==    by 0x804A14A: Program::Program() (Program.cpp:7)
    ==2350==    by 0x804D310: main (Main.cpp:6)
    ==2350==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==2350== 
    ==2350== 
    ==2350== Process terminating with default action of signal 11 (SIGSEGV)
    ==2350==  Bad permissions for mapped region at address 0x0
    ==2350==    at 0x0: ???
    ==2350==    by 0x804D4CF: Block::Block() (Block.cpp:4)
    ==2350==    by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6)
    ==2350==    by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18)
    ==2350==    by 0x804A14A: Program::Program() (Program.cpp:7)
    ==2350==    by 0x804D310: main (Main.cpp:6)
    ==2350== 
    ==2350== HEAP SUMMARY:
    ==2350==     in use at exit: 9,785,834 bytes in 338 blocks
    ==2350==   total heap usage: 583 allocs, 245 frees, 9,862,264 bytes allocated
    ==2350== 
    ==2350== LEAK SUMMARY:
    ==2350==    definitely lost: 0 bytes in 0 blocks
    ==2350==    indirectly lost: 0 bytes in 0 blocks
    ==2350==      possibly lost: 4,118 bytes in 112 blocks
    ==2350==    still reachable: 9,781,716 bytes in 226 blocks
    ==2350==         suppressed: 0 bytes in 0 blocks
    ==2350== Rerun with --leak-check=full to see details of leaked memory
    ==2350== 
    ==2350== For counts of detected and suppressed errors, rerun with: -v
    ==2350== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 88 from 11)
    Segmentation fault
    (Block.cpp:4) being the shader constructor
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  11. Post #1331
    kill yourself
    Protocol7's Avatar
    June 2006
    26,080 Posts
    then put a breakpoint on the constructor and step through it until you find the offending line
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1 (list)

  12. Post #1332
    I gave ••••• enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,425 Posts
    In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  13. Post #1333
    Gold Member
    raccoon12's Avatar
    November 2008
    3,175 Posts
    In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.
    yes
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 4Informative Informative x 1 (list)

  14. Post #1334
    ben1066's Avatar
    August 2009
    1,100 Posts
    How do you define the origin of your models? IIRC Jitter adjusts the origin of rigid bodies to their center of mass.
    Fixed it from help of noone (the guy who made the library), but yes, you're right.
    Reply With Quote Edit / Delete Windows 8 United Kingdom Show Events

  15. Post #1335
    kill yourself
    Protocol7's Avatar
    June 2006
    26,080 Posts
    wow you're a lot of help!!

    Funley, I found this to at least copy files

    static void Main(string[] args)
        {
            DirectoryInfo sourceDir = new DirectoryInfo("c:\\a");
            DirectoryInfo destinationDir = new DirectoryInfo("c:\\b");
    
            CopyDirectory(sourceDir, destinationDir);
    
        }
    
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
        {
            if (!destination.Exists)
            {
                destination.Create();
            }
    
            // Copy all files.
            FileInfo[] files = source.GetFiles();
            foreach (FileInfo file in files)
            {
                file.CopyTo(Path.Combine(destination.FullName, 
                    file.Name));
            }
    
            // Process subdirectories.
            DirectoryInfo[] dirs = source.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                // Get destination directory.
                string destinationDir = Path.Combine(destination.FullName, dir.Name);
    
                // Call CopyDirectory() recursively.
                CopyDirectory(dir, new DirectoryInfo(destinationDir));
            }
        }

    That at least copies the directory, should get you started
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1 (list)

  16. Post #1336
    Gold Member
    raccoon12's Avatar
    November 2008
    3,175 Posts
    wow you're a lot of help!!

    Funley, I found this to at least copy files

    static void Main(string[] args)
        {
            DirectoryInfo sourceDir = new DirectoryInfo("c:\\a");
            DirectoryInfo destinationDir = new DirectoryInfo("c:\\b");
    
            CopyDirectory(sourceDir, destinationDir);
    
        }
    
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
        {
            if (!destination.Exists)
            {
                destination.Create();
            }
    
            // Copy all files.
            FileInfo[] files = source.GetFiles();
            foreach (FileInfo file in files)
            {
                file.CopyTo(Path.Combine(destination.FullName, 
                    file.Name));
            }
    
            // Process subdirectories.
            DirectoryInfo[] dirs = source.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                // Get destination directory.
                string destinationDir = Path.Combine(destination.FullName, dir.Name);
    
                // Call CopyDirectory() recursively.
                CopyDirectory(dir, new DirectoryInfo(destinationDir));
            }
        }

    That at least copies the directory, should get you started
    Honestly, I thought I was in a different thread
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  17. Post #1337
    NoName-'s Avatar
    November 2011
    1,182 Posts
    snip im stupid
    Reply With Quote Edit / Delete Windows XP Argentina Show Events Agree Agree x 1Friendly Friendly x 1Disagree Disagree x 1 (list)

  18. Post #1338
    Gold Member
    Blackwheel's Avatar
    April 2005
    682 Posts
    I'm trying to go through a few sfml tutorials.

    Here are the errors I'm getting:
    sfmlHello.cpp: In function ‘int main()’:
    sfmlHello.cpp:7:16: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
    sfmlHello.cpp:9:17: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’

    Here is the code:
    Code:
    #include <SFML/Graphics.hpp>
    
    int main(){
    	sf::VideoMode VMode(800, 600, 32);
    	sf::RenderWindow Window(VMode, "SFMLCoder Tutorial - Empty Window");
    
    	while (Window.isOpen()){
    		sf::Event Event;
    		while (Window.pollEvent(Event)){
    			switch(Event.Type) {
    			case sf::Event::Closed:
    				Window.Close();
    				break;
    			default:
    				break;
    			}
    		}
    		Window.Clear(sf::Color(0, 255, 255));
    		Window.Display();
    	}
    	return 0;
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #1339
    Gold Member
    ShaunOfTheLive's Avatar
    November 2007
    9,902 Posts
    I'm trying to go through a few sfml tutorials.

    Here are the errors I'm getting:
    sfmlHello.cpp: In function ‘int main()’:
    sfmlHello.cpp:7:16: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
    Are you sure you're using the right version of SFML? SFML 2.0 has "isOpen" and "pollEvent", but SFML 1.6 has "isOpened" and no pollEvent.

    EDIT: Also, you need to include <SFML/Window.hpp>
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  20. Post #1340
    Gold Member
    Blackwheel's Avatar
    April 2005
    682 Posts
    Are you sure you're using the right version of SFML? SFML 2.0 has "isOpen" and "pollEvent", but SFML 1.6 has "isOpened" and no pollEvent.

    EDIT: Also, you need to include <SFML/Window.hpp>
    Tried isOpened and it also didn't recognize that as a member.
    I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #1341
    HQRSE FUCKER
    ief014's Avatar
    September 2009
    3,069 Posts
    Tried isOpened and it also didn't recognize that as a member.
    I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.
    Older SFML versions don't use camel-back notation. It should be IsOpened, not isOpened.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  22. Post #1342
    boy i sure do love it when my title doesnt fit
    LuaChobo's Avatar
    December 2009
    6,495 Posts
    I just remembered why i never learned unrealscript, because OO used to hurt my head.
    I have decided to try and pick it up, Anyone got any tips?
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  23. Post #1343
    olavst's Avatar
    November 2011
    76 Posts
    I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.
    The ubuntu packages are the stable version (1.6). You need to compile the 2.0 version yourself. Not hard, the cmake-gui package can help you if you're unfamiliar with cmake
    Reply With Quote Edit / Delete Linux Norway Show Events

  24. Post #1344
    Official Bro of DD

    June 2010
    13,642 Posts
    -Figure It out-
    Reply With Quote Edit / Delete Windows 7 New Zealand Show Events

  25. Post #1345
    no-named's Avatar
    July 2008
    740 Posts
    I'm trying to minimize the communication between my server and client for example having the server tell the client that a character shoots in one direction, and the client will know what weapon that character is using, what kind of projectile to spawn, and where other players are for the projectile to collide with. Is this is a bad way of doing it because it can potentially be unreliable, or is better because it will reduce lag?
    Reply With Quote Edit / Delete Windows 7 Denmark Show Events

  26. Post #1346
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,831 Posts
    I'm trying to minimize the communication between my server and client for example having the server tell the client that a character shoots in one direction, and the client will know what weapon that character is using, what kind of projectile to spawn, and where other players are for the projectile to collide with. Is this is a bad way of doing it because it can potentially be unreliable, or is better because it will reduce lag?
    As long as you verify everything on your server, it should be fine.

    For example, for a multiplayer game I am (slowly) working on in my spare time, I intend to have the AI be predicted on the client. Whenever an AI updates his movements or behaviors, it will send an update to the relevant clients - in the case of movement, it will simply use vectors, or directions with speed.

    So instead of constantly updating an AI's position while traveling in a straight line, I simply send to the client that an AI is going in a straight line with a certain speed, and let the client predict it.

    Cuts down on networking, but minimalizes chances of cheating and such because things are still verified by the server. While this means there may be client issues (such as slightly teleporting AI), I personally think it's the best approach.

    So you can do your idea there, but just be sure you keep track of everything so you can verify it on the server. While you should never trust your clients to make decisions, there's no reason to hold their hand through everything - just be sure you can verify any important decisions like shooting or movement.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  27. Post #1347
    Gold Member

    March 2012
    39 Posts
    I just remembered why i never learned unrealscript, because OO used to hurt my head.
    I have decided to try and pick it up, Anyone got any tips?
    Mess around with UTGame and see how it works before trying to inherit from the UDK or non-UDK bases. There's a few tutorials around (see UDKGems) but you're best off learning from the documentation at UDN and code that ships with the UDK (UnCodeX is a brilliant program).

    Don't edit anything in any of the Development/Src/ folders that already exist however, always derive.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  28. Post #1348
    Gold Member
    Blackwheel's Avatar
    April 2005
    682 Posts
    thanks for the help guys
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 2 (list)

  29. Post #1349
    Richy19's Avatar
    May 2010
    5,408 Posts
    Anyon know the formula for accessing element in a 1D array that has been created for 3D?

    Like with a 2d one its:
    blah ar[X*Y];
    ar[X + Y*Width];
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  30. Post #1350
    Zeonho's Avatar
    June 2010
    309 Posts
    Anyon know the formula for accessing element in a 1D array that has been created for 3D?

    Like with a 2d one its:
    blah ar[X*Y];
    ar[X + Y*Width];
    http://www.facepunch.com/threads/109...1#post31830255
    Reply With Quote Edit / Delete Windows Vista Germany Show Events

  31. Post #1351
    Programming King and Most Patient Member 2013
    r0b0tsquid's Avatar
    December 2008
    1,244 Posts
    Anyon know the formula for accessing element in a 1D array that has been created for 3D?

    Like with a 2d one its:
    blah ar[X*Y];
    ar[X + Y*Width];
    It's the x value...
    plus the y value time the width of a row...
    plus z value times the number of elements in an xy slice (width * height).
    The width factors out, so you get this:

    Code:
    array[x + (y + z * height) * width]
    You'll notice that this bit
    Code:
    y + z * height
    looks a lot like what you had for 2D:
    Code:
    X + Y*Width
    ...which is because it is a lot like that.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Winner Winner x 2Programming King Programming King x 1 (list)

  32. Post #1352
    Richy19's Avatar
    May 2010
    5,408 Posts
    Im trying to read a text file to start with text drawing in OGL, for it I use this method:
    bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile, int heightSize, int widthSize )
    {
        bool result = bitmap.LoadFromFile(imageFile.c_str());
        std::ifstream myfile;
    
        try
        {
            myfile.open(fontFile.c_str());
            if (myfile.is_open())
            {
                int arrVal = 0;
                while ( myfile.good() )
                {
                    std::string line;
                    std::getline (myfile,line);
    
                    int numS = 0;
                    int lineSp = 0;
                    int posVal = 0;
    
                    while(lineSp < line.size())
                    {
                        if(line.at(lineSp) == ' ')
                        {
                            Positions[arrVal][posVal] = atoi(line.substr(numS, lineSp - numS).c_str());
                            numS = lineSp + 1;
                            posVal++;
                        }
    
    
                        lineSp++;
                    }
    
                    arrVal++;
                }
                myfile.close();
            }
        }
        catch(int e)
        {
            myfile.close();
            result = false;
        }
    
        for(int i = 0; i < 256; i++)
        {
            std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":"<< Positions[i][3] << std::endl;
        }
    
        return result;
    }

    And the file I am reading is this:
    Code:
    0 0 0 0
    10 0 10 16
    20 0 10 16
    30 0 10 16
    40 0 10 16
    50 0 10 16
    60 0 10 16
    70 0 10 16
    80 0 10 16
    90 0 0 0
    100 0 0 0
    110 0 10 16
    120 0 10 16
    130 0 0 0
    140 0 10 16
    150 0 10 16
    0 16 10 16
    10 16 10 16
    20 16 10 16
    30 16 10 16
    40 16 10 16
    50 16 10 16
    60 16 10 16
    70 16 10 16
    80 16 10 16
    90 16 10 16
    100 16 10 16
    110 16 10 16
    120 16 10 16
    130 16 10 16
    140 16 10 16
    150 16 10 16
    0 32 10 16
    10 32 3 16
    20 32 6 16
    30 32 10 16
    40 32 10 16
    50 32 10 16
    60 32 10 16
    70 32 3 16
    80 32 5 16
    90 32 5 16
    100 32 10 16
    110 32 10 16
    120 32 3 16
    130 32 6 16
    140 32 3 16
    150 32 10 16
    0 48 10 16
    10 48 5 16
    20 48 10 16
    30 48 10 16
    40 48 10 16
    50 48 10 16
    60 48 10 16
    70 48 10 16
    80 48 10 16
    90 48 10 16
    100 48 3 16
    110 48 3 16
    120 48 6 16
    130 48 10 16
    140 48 6 16
    150 48 10 16
    0 64 10 16
    10 64 10 16
    20 64 10 16
    30 64 10 16
    40 64 10 16
    50 64 10 16
    60 64 10 16
    70 64 10 16
    80 64 10 16
    90 64 10 16
    100 64 10 16
    110 64 10 16
    120 64 10 16
    130 64 10 16
    140 64 10 16
    150 64 10 16
    0 80 10 16
    10 80 10 16
    20 80 10 16
    30 80 10 16
    40 80 10 16
    50 80 10 16
    60 80 10 16
    70 80 10 16
    80 80 10 16
    90 80 10 16
    100 80 10 16
    110 80 5 16
    120 80 10 16
    130 80 5 16
    140 80 6 16
    150 80 10 16
    0 96 3 16
    10 96 10 16
    20 96 10 16
    30 96 10 16
    40 96 10 16
    50 96 10 16
    60 96 10 16
    70 96 10 16
    80 96 10 16
    90 96 3 16
    100 96 10 16
    110 96 10 16
    120 96 10 16
    130 96 10 16
    140 96 10 16
    150 96 10 16
    0 112 10 16
    10 112 10 16
    20 112 10 16
    30 112 10 16
    40 112 10 16
    50 112 10 16
    60 112 10 16
    70 112 10 16
    80 112 10 16
    90 112 10 16
    100 112 10 16
    110 112 6 16
    120 112 3 16
    130 112 6 16
    140 112 10 16
    150 112 10 16
    0 128 10 16
    10 128 10 16
    20 128 10 16
    30 128 10 16
    40 128 10 16
    50 128 10 16
    60 128 10 16
    70 128 10 16
    80 128 10 16
    90 128 10 16
    100 128 10 16
    110 128 10 16
    120 128 10 16
    130 128 10 16
    140 128 10 16
    150 128 10 16
    0 144 10 16
    10 144 10 16
    20 144 10 16
    30 144 10 16
    40 144 10 16
    50 144 10 16
    60 144 10 16
    70 144 10 16
    80 144 10 16
    90 144 10 16
    100 144 10 16
    110 144 10 16
    120 144 10 16
    130 144 10 16
    140 144 10 16
    150 144 10 16
    0 160 10 16
    10 160 3 16
    20 160 10 16
    30 160 10 16
    40 160 10 16
    50 160 10 16
    60 160 3 16
    70 160 10 16
    80 160 10 16
    90 160 10 16
    100 160 5 16
    110 160 10 16
    120 160 10 16
    130 160 10 16
    140 160 10 16
    150 160 10 16
    0 176 6 16
    10 176 10 16
    20 176 6 16
    30 176 6 16
    40 176 5 16
    50 176 10 16
    60 176 10 16
    70 176 6 16
    80 176 5 16
    90 176 5 16
    100 176 6 16
    110 176 10 16
    120 176 10 16
    130 176 10 16
    140 176 10 16
    150 176 10 16
    0 192 10 16
    10 192 10 16
    20 192 10 16
    30 192 10 16
    40 192 10 16
    50 192 10 16
    60 192 10 16
    70 192 10 16
    80 192 10 16
    90 192 10 16
    100 192 10 16
    110 192 10 16
    120 192 10 16
    130 192 10 16
    140 192 10 16
    150 192 10 16
    0 208 10 16
    10 208 10 16
    20 208 10 16
    30 208 10 16
    40 208 10 16
    50 208 10 16
    60 208 10 16
    70 208 6 16
    80 208 10 16
    90 208 10 16
    100 208 10 16
    110 208 10 16
    120 208 10 16
    130 208 10 16
    140 208 10 16
    150 208 10 16
    0 224 10 16
    10 224 10 16
    20 224 10 16
    30 224 10 16
    40 224 10 16
    50 224 10 16
    60 224 10 16
    70 224 10 16
    80 224 10 16
    90 224 10 16
    100 224 10 16
    110 224 10 16
    120 224 5 16
    130 224 5 16
    140 224 6 16
    150 224 6 16
    0 240 10 16
    10 240 10 16
    20 240 10 16
    30 240 10 16
    40 240 10 16
    50 240 10 16
    60 240 10 16
    70 240 6 16
    80 240 10 16
    90 240 10 16
    100 240 10 16
    110 240 10 16
    120 240 10 16
    130 240 10 16
    140 240 10 16
    150 240 10 1
    But the output from cout is:
    Code:
    :::
    
    ::
    :
    ::
    :
    ::
    :	
    (::
    :	
    2::
    :�
    <::
    :
    F::
    :
    P::
    :	
    Z:::	
    d:::	
    n::
    :
    x::
    :
    �:::
    �::
    :
    �::
    :
    ::
    :	
    
    ::
    :�
    ::
    :
    ::
    :	
    (::
    :	
    2::
    :	
    <::
    :	
    F::
    :
    P::
    :
    Z::
    :
    d::
    :
    n::
    :
    x::
    :
    �::
    :
    �::
    :
    �::
    :�
    : :
    :
    
    : ::
    : ::
    : :
    :
    (: :
    :
    2: :
    :
    <: :
    :
    F: ::M
    P: ::
    Z: ::
    d: :
    :
    n: :
    :
    x: ::
    �: ::	
    �: ::
    �: :
    :
    :0:
    :
    
    :0::	
    :0:
    :
    :0:
    :	
    (:0:
    :
    2:0:
    :
    <:0:
    :
    F:0:
    :
    P:0:
    :
    Z:0:
    :
    d:0::
    n:0::
    x:0::
    �:0:
    :	
    �:0::
    �:0:
    :
    :@:
    :
    
    :@:
    :
    :@:
    :
    :@:
    :	
    (:@:
    :�
    2:@:
    :
    <:@:
    :
    F:@:
    :
    P:@:
    :
    Z:@:
    :
    d:@:
    :
    n:@:
    :
    x:@:
    :
    �:@:
    :
    �:@:
    :
    �:@:
    :	
    :P:
    :
    
    :P:
    :
    :P:
    :
    :P:
    :
    (:P:
    :
    2:P:
    :
    <:P:
    :
    F:P:
    :
    P:P:
    :
    Z:P:
    :
    d:P:
    :
    n:P::
    x:P:
    :
    �:P::	
    �:P::
    �:P:
    :0
    :`::
    
    :`:
    :�
    :`:
    :
    :`:
    :	
    (:`:
    :�
    2:`:
    :
    <:`:
    :
    F:`:
    :
    P:`:
    :
    Z:`::
    d:`:
    :
    n:`:
    :
    x:`:
    :
    �:`:
    :
    �:`:
    :
    �:`:
    :
    :p:
    :
    
    :p:
    :	
    :p:
    :
    :p:
    :
    (:p:
    :
    2:p:
    :�
    <:p:
    :
    F:p:
    :	
    P:p:
    :
    Z:p:
    :
    d:p:
    :
    n:p::
    x:p::q
    �:p::
    �:p:
    :
    �:p:
    :
    :�:
    :
    
    :�:
    :
    :�:
    :
    :�:
    :	
    (:�:
    :
    2:�:
    :
    <:�:
    :
    F:�:
    :
    P:�:
    :�
    Z:�:
    :�
    d:�:
    :
    n:�:
    :
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :�
    :�:
    :�
    
    :�:
    :�
    :�:
    :
    :�:
    :�
    (:�:
    :
    2:�:
    :�
    <:�:
    :
    F:�:
    :
    P:�:
    :
    Z:�:
    :
    d:�:
    :
    n:�:
    :
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :
    :�:
    :
    
    :�::	
    :�:
    :
    :�:
    :
    (:�:
    :
    2:�:
    :
    <:�::
    F:�:
    :	
    P:�:
    :�
    Z:�:
    :
    d:�::
    n:�:
    :
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :
    :�::�
    
    :�:
    :
    :�::
    :�::
    (:�::
    2:�:
    :
    <:�:
    :
    F:�::
    P:�::�
    Z:�::�
    d:�::
    n:�:
    :
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :
    :�:
    :�
    
    :�:
    :�
    :�:
    :
    :�:
    :�
    (:�:
    :
    2:�:
    :�
    <:�:
    :
    F:�:
    :
    P:�:
    :�
    Z:�:
    :
    d:�:
    :
    n:�:
    :
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :
    :�:
    :�
    
    :�:
    :�
    :�:
    :�
    :�:
    :�
    (:�:
    :
    2:�:
    :
    <:�:
    :
    F:�::
    P:�:
    :
    Z:�:
    :
    d:�:
    :
    n:�:
    :	
    x:�:
    :
    �:�:
    :
    �:�:
    :
    �:�:
    :	
    :�:
    :
    
    :�:
    :�
    :�:
    :
    :�:
    :
    (:�:
    :
    2:�:
    :�
    <:�:
    :
    F:�:
    :
    P:�:
    :
    Z:�:
    :
    d:�:
    :
    n:�:
    :
    x:�::
    �:�::�
    �:�::
    �:�::	
    :�:
    :
    
    :�:
    :�
    :�:
    :
    :�:
    :
    (:�:
    :
    2:�:
    :�
    <:�:
    :
    F:�::
    P:�:
    :
    Z:�:
    :
    d:�:
    :
    n:�:
    :
    x:�:
    :	
    �:�:
    :
    �:�:
    :
    �:�:
    :
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Optimistic Optimistic x 1 (list)

  33. Post #1353
    kill yourself
    Protocol7's Avatar
    June 2006
    26,080 Posts
    Try something like this

    Edited:

    std::stringstream ss(s);
    std::string item;    
    while(std::getline(ss, item, ' ')) {
        Positions[arrVal][posVal] = atoi(item);    
    }

    string::getline has a very nice delimiter parameter that does what you want

    Edited:

    Oh, I forgot, s in the stringstream would be your string

    either that or you could just declare the stringstream and do stringstream.str
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  34. Post #1354
    Richy19's Avatar
    May 2010
    5,408 Posts
    I got it working by changing the file format to:
    Code:
    0000 0000 0000 0000
    0010 0000 0010 0016
    0020 0000 0010 0016
    0030 0000 0010 0016
    0040 0000 0010 0016
    0050 0000 0010 0016
    0060 0000 0010 0016
    0070 0000 0010 0016
    0080 0000 0010 0016
    0090 0000 0000 0000
    0100 0000 0000 0000
    0110 0000 0010 0016
    0120 0000 0010 0016
    0130 0000 0000 0000
    0140 0000 0010 0016
    0150 0000 0010 0016
    0000 0016 0010 0016
    0010 0016 0010 0016
    0020 0016 0010 0016
    0030 0016 0010 0016
    ...
    IE 4 digits per number

    and the code I use now is:
    bool result = bitmap.LoadFromFile(imageFile.c_str());
        std::ifstream myfile;
    
        try
        {
            myfile.open(fontFile.c_str());
            if (myfile.is_open())
            {
                int arrVal = 0;
                while ( myfile.good() )
                {
                    std::string line;
                    std::getline (myfile,line);
    
                    int jump = 0;
                    for( int n = 0; n < 4; n++)
                    {
                        std::string str = "";
                        int numb = 0;
                        int pos = n*5;
    
                        str += line[pos];
                        str += line[pos+1];
                        str += line[pos+2];
                        str += line[pos+3];
    
    
                        std::istringstream ( str ) >> numb;
    
                        Positions[arrVal][0+n] = numb;
                    }
    
    
                    arrVal++;
                }
                myfile.close();
            }
        }
        catch(int e)
        {
            myfile.close();
            result = false;
        }
    
        for(int i = 0; i < 256; i++)
        {
            std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":"<< Positions[i][3] << std::endl;
        }
    std::cout << "Blah" << std::endl;
    

    which outputs correctly but creates a segfault on returning, do i have to flush a buffer or something that I have missed out?

    Edited:

    the call stack is:

    #0 0x284c6c ??() (/usr/lib/i386-linux-gnu/libstdc++.so.6:??)
    #1 0x284cfe std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() () (/usr/lib/i386-linux-gnu/libstdc++.so.6:??)
    #2 0x804fb1b Program::Initialize(this=0x808c7d8) (/home/richy/codeblocks/FPS/src/Program.cpp:33)
    #3 0x8052b3a main() (/home/richy/codeblocks/FPS/src/Main.cpp:7)
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  35. Post #1355
    kill yourself
    Protocol7's Avatar
    June 2006
    26,080 Posts
    segfaults with arrays is usually caused by trying to access an index that doesn't exist in the array

    don't know your specific cause since your code looks good to me but it's worth looking into
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  36. Post #1356
    Richy19's Avatar
    May 2010
    5,408 Posts
    Im putting up the class code incase anyone can see anything:
    #ifndef BITMAPTEXT_HPP_INCLUDED
    #define BITMAPTEXT_HPP_INCLUDED
    
    
    #include <GL/gl.h>
    #include <vector>
    #include "soglf/Texture.hpp"
    
    namespace SOGLF
    {
    ///
    /// \brief Class for displaying text onscreen Not implemented yet
    ///
    class BitmapText
    {
    protected:
        GLuint vertexbuffer;
        GLuint uvbuffer;
        std::vector<GLuint> VertexList;
        std::vector<GLuint> UVList;
        SOGLF::Texture bitmap;
        unsigned short Positions[256][4];
    public:
        ///
        /// \brief Empty constructor
        ///
        BitmapText();
    
        ///
        /// \brief Empty deconstructor
        ///
        ~BitmapText();
    
        ///
        /// \brief Construct class from given arguments
        /// \param Bitmap image
        /// \param Bitmap position array
        /// \param Character size used
        /// \param Text to display
        bool LoadFile(const std::string& imageFile, const std::string& fontFile , int heightSize, int widthSize);
    
        ///
        /// \brief Set text
        ///
        void SetText(const std::string& text);
    };
    }
    
    #endif // BITMAPTEXT_HPP_INCLUDED
    

    
    #include <GL/glew.h>
    #include "soglf/BitmapText.hpp"
    #include <GL/glfw.h>
    #include <iostream>
    #include <fstream>
    #include "soglf/Utilities.hpp"
    
    
    SOGLF::BitmapText::BitmapText()
    {
        glGenBuffers(1, &vertexbuffer);
        glGenBuffers(1, &uvbuffer);
    }
    
    SOGLF::BitmapText::~BitmapText()
    {
        glDeleteBuffers(1, &vertexbuffer);
        glDeleteBuffers(1, &uvbuffer);
    }
    
    bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile, int heightSize, int widthSize )
    {
        bool result = bitmap.LoadFromFile(imageFile.c_str());
        std::ifstream myfile;
    
        try
        {
            myfile.open(fontFile.c_str());
            if (myfile.is_open())
            {
                int arrVal = 0;
                while ( myfile.good() )
                {
                    std::string line;
                    std::getline (myfile,line);
    
                    for( int n = 0; n < 4; n++)
                    {
                        std::string str = "";
                        int numb = 0;
                        int pos = n*5;
    
                        str += line[pos];
                        str += line[pos+1];
                        str += line[pos+2];
                        str += line[pos+3];
    
    
                        std::istringstream ( str ) >> numb;
    
                        Positions[arrVal][0+n] = numb;
                    }
    
    
                    arrVal++;
                }
                myfile.close();
            }
    
            for(int i = 0; i < 256; i++)
            {
                std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":" << Positions[i][3] << std::endl;
            }
        }
        catch(int e)
        {
            std::cout << "Failed to load: " << fontFile << std::endl;
            result = false;
        }
    
    std::cout << "Blah";
    
        return result;
    }
    
    void SOGLF::BitmapText::SetText(const std::string& text)
    {
    
    }
    

    Edited:

    Changed it from an array of short to just a vector of vec4 and works as planned.
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  37. Post #1357
    Richy19's Avatar
    May 2010
    5,408 Posts
    OK so I think I have everything setup so that it should draw... but it doesnt.
    this is my Orthogonal:
    SOGLF::Matrices::Orthogonal =
            glm::ortho(
                0,
                winW,
                winH,
                0,
                1,
                -1
            );

    these are the shaders:
    #version 120
    uniform mat4 MVP;
    attribute vec4 Position;
    attribute vec2 UV;
    varying vec2 uv;
    
    void main(){
        uv = UV;
        gl_Position =  MVP * Position;
    }

    #version 120
    varying vec2 uv;
    uniform sampler2D Texture;
    uniform vec4 Color;
    void main(){
    	vec4 textur = texture2D( Texture, uv ).rgba;
    	if(textur.rgb == vec3(1.0f,1.0f,1.0f))    textur.a = Color.a;
    	textur.rgb = Color.rgb;	
    	gl_FragColor = textur;
    }

    The header :

    #ifndef BITMAPTEXT_HPP_INCLUDED
    #define BITMAPTEXT_HPP_INCLUDED
    
    
    #include <GL/gl.h>
    #include <vector>
    #include "soglf/Texture.hpp"
    #include "soglf/Drawable.hpp"
    #include "soglf/Shader.hpp"
    
    namespace SOGLF
    {
    ///
    /// \brief Class for displaying text onscreen Not implemented yet
    ///
    class BitmapText : public SOGLF::Drawable
    {
    protected:
        GLuint vertexbuffer;
        GLuint uvbuffer;
        std::vector<GLfloat> VertexList;
        std::vector<GLfloat> UVList;
        SOGLF::Texture bitmap;
        SOGLF::Shader shader;
        std::vector<glm::vec4> Positions;
        glm::vec2 Pos;
        std::string text;
        glm::vec4 Color;
    
        glm::mat4 MVP;
    
        GLuint TextureID;
        GLuint ColorID;
        GLuint MVPID;
        GLuint PositionID;
        GLuint UVID;
    
        void Rebuild();
    public:
        ///
        /// \brief Empty constructor
        ///
        BitmapText();
    
        ///
        /// \brief Empty deconstructor
        ///
        ~BitmapText();
    
        ///
        /// \brief Construct class from given arguments
        /// \param Bitmap image
        /// \param Bitmap position array
        bool LoadFile(const std::string& imageFile, const std::string& fontFile );
    
        ///
        /// \brief Set text
        ///
        void SetText(const std::string& eText);
    
        void SetPosition(const glm::vec2 &pos);
    
        virtual void Update();
    
        virtual void Draw();
    };
    }
    
    #endif // BITMAPTEXT_HPP_INCLUDED

    and the cpp
    #include <GL/glew.h>
    #include "soglf/BitmapText.hpp"
    #include <GL/glfw.h>
    #include <iostream>
    #include <fstream>
    #include "soglf/Utilities.hpp"
    #include "soglf/Window.hpp"
    
    
    SOGLF::BitmapText::BitmapText():
        shader("./Resources/text.vert" , "./Resources/text.frag")
    {
        Pos = glm::vec2(0.0f);
        Color = glm::vec4(1.0f);
        text = "hi";
    
        glGenBuffers(1, &vertexbuffer);
        glGenBuffers(1, &uvbuffer);
    
        MVPID = glGetUniformLocation(shader.GetShaderID(), "MVP");
        TextureID = glGetUniformLocation(shader.GetShaderID(), "Texture");
        PositionID = glGetAttribLocation(shader.GetShaderID(), "Position");
        UVID = glGetAttribLocation(shader.GetShaderID(), "UV");
        ColorID = glGetUniformLocation(shader.GetShaderID(), "Color");
    
    }
    
    SOGLF::BitmapText::~BitmapText()
    {
        glDeleteBuffers(1, &vertexbuffer);
        glDeleteBuffers(1, &uvbuffer);
    }
    
    bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile )
    {
        bool result = bitmap.LoadFromFile(imageFile.c_str());
        std::ifstream myfile;
    
        try
        {
            myfile.open(fontFile.c_str());
            if (myfile.is_open())
            {
                while ( myfile.good() )
                {
                    std::string line;
                    std::getline (myfile,line);
    
                    float x,y,z,w;
    
                    std::stringstream strx, stry, strz, strw;
    
                    strx << line[0]     << line[1]  << line[2]  << line[3];
                    stry << line[5]     << line[6]  << line[7]  << line[8];
                    strz << line[10]    << line[11] << line[12] << line[13];
                    strw << line[15]    << line[16] << line[17] << line[18];
    
                    strx  >> x;  stry  >> y;  strz  >> z;  strw  >> w;
    
                    Positions.push_back(glm::vec4(x, y, z, w));
    
                }
                myfile.close();
            }
    
            //for (unsigned int i = 0; i < Positions.size(); i++)
            //{
            //std::cout << Positions[i].x << ":" << Positions[i].y << ":" << Positions[i].z << ":" << Positions[i].w << std::endl;
            //}
        }
        catch(int e)
        {
            std::cout << "Failed to load: " << fontFile << std::endl;
            result = false;
        }
    
    
        return result;
    }
    
    void SOGLF::BitmapText::SetText(const std::string& eText)
    {
        text = eText;
        Rebuild();
    }
    
    void SOGLF::BitmapText::SetPosition(const glm::vec2& pos)
    {
        Pos = pos;
        Rebuild();
    }
    
    void SOGLF::BitmapText::Update()
    {
    
    }
    
    void SOGLF::BitmapText::Draw()
    {
    shader.Bind();
    glUniformMatrix4fv(MVPID, 1, GL_FALSE, &MVP[0][0]);
    
    glActiveTexture(GL_TEXTURE0);
    bitmap.Bind();
    glUniform1i(TextureID, 0);
    
    glUniform4fv(ColorID,1 , &Color[0]);
    
    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
        );
    
    glEnableVertexAttribArray(UVID);
        glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
        glVertexAttribPointer(
            UVID,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            2,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );
    
    glDrawArrays(GL_TRIANGLES, 0, VertexList.size()/3);
    
    glDisableVertexAttribArray(PositionID);
        glDisableVertexAttribArray(UVID);
    
    SOGLF::Texture::Unbind();
    SOGLF::Shader::Unbind();
    }
    
    void SOGLF::BitmapText::Rebuild()
    {
        VertexList.clear();
        UVList.clear();
    
        glm::vec2 winS = SOGLF::WindowClass::Window.GetSize();
        float disp = 0.0f;
        for(int i = 0; i < text.size(); i++)
        {
            glm::vec4 charRect = Positions[text.c_str()[i]];
    
    
            VertexList.push_back(0.0f + disp);
            VertexList.push_back(charRect.w/winS.y);
            VertexList.push_back(0.0f);
    
            VertexList.push_back(0.0f + disp);
            VertexList.push_back(0.0f);
            VertexList.push_back(0.0f);
    
            VertexList.push_back(charRect.z/winS.x + disp);
            VertexList.push_back(charRect.w/winS.y);
            VertexList.push_back(0.0f);
    
            VertexList.push_back(charRect.z/winS.x + disp);
            VertexList.push_back(charRect.w/winS.y);
            VertexList.push_back(0.0f);
    
            VertexList.push_back(0.0f + disp);
            VertexList.push_back(0.0f);
            VertexList.push_back(0.0f);
    
            VertexList.push_back(charRect.z/winS.x + disp);
            VertexList.push_back(0.0f);
            VertexList.push_back(0.0f);
    
            UVList.push_back(charRect.x / bitmap.GetSize().x);
            UVList.push_back(charRect.y / bitmap.GetSize().y);
    
            UVList.push_back(charRect.x / bitmap.GetSize().x);
            UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);
    
            UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
            UVList.push_back(charRect.y / bitmap.GetSize().y);
    
            UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
            UVList.push_back(charRect.y / bitmap.GetSize().y);
    
            UVList.push_back(charRect.x / bitmap.GetSize().x);
            UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);
    
            UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
            UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);
    
            disp += charRect.z;
        }
    
    
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glBufferData(GL_ARRAY_BUFFER, VertexList.size() * sizeof(GLfloat), &VertexList[0], GL_STATIC_DRAW);
    
        glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
        glBufferData(GL_ARRAY_BUFFER, UVList.size() * sizeof(GLfloat), &UVList[0], GL_STATIC_DRAW);
    
        Model = glm::translate(Pos.x/winS.x , Pos.y/winS.y, 0.0f);
        MVP = SOGLF::Matrices::Matrix.GetOrthogonal() * Model;
    }
    

    I dont get any errors, or anything. Simply nothing displays.
    I tried changing the shader so that it would just dsplay a black vertex but nothing showed up either.
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  38. Post #1358
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,756 Posts
    OK so I think I have everything setup so that it should draw... but it doesnt.
    Talk to me on steam or gmail chat (naelstrof@gmail.com); I develop on Linux as well and can help you out.
    I find forums an uncomfortable place to help you when you have so many questions and so much code.
    Reply With Quote Edit / Delete Linux United States Show Events

  39. Post #1359

    January 2012
    421 Posts
    Talk to me on steam or gmail chat (naelstrof@gmail.com); I develop on Linux as well and can help you out.
    I find forums an uncomfortable place to help you when you have so many questions and so much code.
    Y'know for someone posting in the programmers section, you should really realize how easy it is to write a web scraper for emails.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Agree Agree x 1Optimistic Optimistic x 1 (list)

  40. Post #1360
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,756 Posts
    I want to chat with him; I do not want to use email or forums.
    Reply With Quote Edit / Delete Linux United States Show Events