Jump to content
  • Advertisement

sn0k3

Member
  • Content Count

    33
  • Joined

  • Last visited

Community Reputation

560 Good

About sn0k3

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. sn0k3

    Video Content in a Game

    You can try writing your own player for the format which the player will support.That means you can write a player, which supports a format which you want to support! :)
  2. You should decide what game engine you want to use.I mean a game engine like Construct or like Unreal Engine or Unity3d. If you don't want to use game engine like these and if you want to create a game and to write everything, then you can try frameworks or try to build your own framework.There are some good frameworks for an example: SDL, SFML, Alegro. They aren't bad.They use C++.SFML supports other languages too! If you want to build a framework then you can try OpenGL or DirectX.
  3. Thank you for the info, and I already did frame.setResizable(false); Thank you guys!
  4. Okay, but isn't paint(Graphics g); method called by itself? I mean you shouldn't call it?
  5. Hello guys, I was testing Java 2D and I tryed to make a game using Canvas and JFrame.There is interesting thing.For now it is drawing rectangle / square /, but when a key is pressed ( up ), it should be moving that rectangle, but it isn't..The Vector2f, which stores the position of the sprite is updated, but the sprite isn't repainted on a new position..   Code:   Window class: public class Window extends Canvas implements Runnable {          private boolean isRunning = true;     private InputHandler inputHandler;          public static Vector2f positionOfTheSquare;          public Window() {         inputHandler = new InputHandler();         addKeyListener(inputHandler);                  positionOfTheSquare = new Vector2f(675 / 2, 25);     }          public void paint(Graphics g) { //        g.drawRect(675 / 2, 25, 25, 25);         g.drawRect((int)positionOfTheSquare.x, (int)positionOfTheSquare.y, 25, 25);             }          public void update() {         if(inputHandler.keys[0] == true) {             positionOfTheSquare.y = positionOfTheSquare.y + 25;         }     }          public void render(Graphics g) {     }          public void run() {         while(isRunning == true) {             update();         }     } } InputHandler: public class InputHandler implements KeyListener {     public boolean[] keys = new boolean[4];          public void keyPressed(KeyEvent e) {         if(e.getKeyCode() == KeyEvent.VK_UP) {             keys[0] = true;             System.out.println("Pressed Up!"); //            Window.positionOfTheSquare.y = Window.positionOfTheSquare.y - 25;         }          //        if(e.getK)     }     public void keyReleased(KeyEvent e) {         if(e.getKeyCode() == KeyEvent.VK_UP) {             keys[0] = false;         }     }     public void keyTyped(KeyEvent e) {              } }   and the main class is: public class Main {     public static void main(String[] args) {         JFrame frame = new JFrame("Test");         frame.setSize(new Dimension(640, 480));         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.setLocationRelativeTo(null);                  Window window = new Window();         frame.add(window);         frame.setVisible(true);     } } Any ideas?
  6. sn0k3

    Error with shaders - OpenGL

    I found the error! The error wasn't because of shader, it was in main.cpp file..   The error was this:     Shader shader("shaders/shader.vert", "shaders/shader.vert");   It was passed only vertex shader, and actually yes..The second shader was compiled as frag shader.. I fixed it:     Shader shader("shaders/shader.vert", "shaders/shader.frag");   Thank you!
  7. sn0k3

    Error with shaders - OpenGL

    I changed it, but still the same error!
  8. sn0k3

    Error with shaders - OpenGL

    Frag shader:   #version 330 core layout (location = 0) out vec4 color; void main() {     color = vec4(1.0, 1.0, 1.0, 1.0); }   The vert shader is up.
  9. sn0k3

    Error with shaders - OpenGL

    Other error: Fragment shader failed to compile with the following errors: ERROR: 0:11: error(#143) Undeclared identifier: gl_Position WARNING: 0:11: warning(#402) Implicit truncation of vector from size: 4 to size:  1 ERROR: error(#273) 1 compilation errors.  No code generated   Any ideas why?
  10. sn0k3

    Error with shaders - OpenGL

    @Gooey My wrong.. :D I've pasted it wrong.. It should be:     std::string vertSourceString = FileUtils::read_file(m_VertPath);     const char* vertSource = vertSourceString.c_str();         glShaderSource(vertex, 1, &vertSource, NULL);   But I've posted this:         std::string vertSourceString = FileUtils::read_file(m_VertPath);         std::string fragSourceString = FileUtils::read_file(m_FragPath);         const char* vertSource = FileUtils::read_file(m_VertPath).c_str();         const char* fragSource = FileUtils::read_file(m_FragPath).c_str();         glShaderSource(vertex, 1, vertSourceString.c_str(), NULL);   So other thing, when I put cout to print the fragSource of FragSourceString        std::cout << "Fragment source file: " << fragSource << std::endl; this prints the content of the shader..
  11. sn0k3

    Error with shaders - OpenGL

    @Sagaceil I tryed this now         std::string vertSourceString = FileUtils::read_file(m_VertPath);         std::string fragSourceString = FileUtils::read_file(m_FragPath);         const char* vertSource = FileUtils::read_file(m_VertPath).c_str();         const char* fragSource = FileUtils::read_file(m_FragPath).c_str();         glShaderSource(vertex, 1, vertSourceString.c_str(), NULL); there are new errors: Error    1    error C2102: '&' requires l-value Error    2    error C2198: 'PFNGLSHADERSOURCEPROC' : too few arguments for call   EDIT: I saw, that I forgot to implement two functions (enable and disable) void Shader::enable() const     {         glUseProgram(m_ShaderID);     }     void Shader::disable() const     {         glUseProgram(0);     }   Again compiled, but there is the same error..
  12. sn0k3

    Error with shaders - OpenGL

    Gooey I think yes.   The class, which has function to load (read) a file:     class FileUtils {     public:         static std::string read_file(const char* filePath)         {             FILE* file = fopen(filePath, "rt");             fseek(file, 0, SEEK_END);             unsigned long length = ftell(file);             char* data = new char[length + 1];             memset(data, 0, length + 1);             fseek(file, 0, SEEK_SET);             fread(data, 1, length, file);             fclose(file);             std::string result(data);             delete[] data;             return result;         }     };     And my shader.cpp file, which is used for loading the shaders and enabling them:         Shader::Shader(const char* vertexFilePath, const char* fragFilePath)     {         m_VertPath = vertexFilePath;         m_FragPath = fragFilePath;         m_ShaderID = load();     }     Shader::~Shader()     {         glDeleteProgram(m_ShaderID);     }     GLuint Shader::load()     {         GLuint program = glCreateProgram();         GLuint vertex = glCreateShader(GL_VERTEX_SHADER);         GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);         const char* vertSource = FileUtils::read_file(m_VertPath).c_str();         const char* fragSource = FileUtils::read_file(m_FragPath).c_str();         glShaderSource(vertex, 1, &vertSource, NULL);         glCompileShader(vertex);         GLint result;         glGetShaderiv(vertex, GL_COMPILE_STATUS, &result);         if(result == GL_FALSE)         {             GLint length;             glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length);             std::vector<char> error(length);             glGetShaderInfoLog(vertex, length, &length, &error[0]);             std::cout << "Failed to compile shader!" << std::endl;             std::cout << &error[0] << std::endl;             glDeleteShader(vertex);             return 0;         }         glShaderSource(fragment, 1, &fragSource, NULL);         glCompileShader(fragment);         glGetShaderiv(fragment, GL_COMPILE_STATUS, &result);         if(result == GL_FALSE)         {             GLint length;             glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length);             std::vector<char> error(length);             glGetShaderInfoLog(fragment, length, &length, &error[0]);             std::cout << "Failed to compile shader!" << std::endl;             std::cout << &error[0] << std::endl;             glDeleteShader(fragment);             return 0;         }         glAttachShader(program, vertex);         glAttachShader(program, fragment);         glLinkProgram(program);         glValidateProgram(program);         glDeleteShader(vertex);         glDeleteShader(fragment);         return program;     }     void Shader::enable() const     {     }     void Shader::disable() const     {     }  
  13. Hello guys! When I compile there is an error, which says:   Failed to compile shader! Vertex shader failed to compile with the following errors: ERROR: 0:1: error(#132) Syntax error: "<" parse error ERROR: error(#273) 1 compilation errors.  No code generated   Here you go my vertex shader: #version 330 core layout (location = 0) in vec4 position; uniform mat4 pr_matrix = mat4(1.0); uniform mat4 vw_matrix = mat4(1.0); uniform mat4 ml_matrix = mat4(1.0); void main() {     gl_Position = position; }   Any ideas?
  14. sn0k3

    Bugs in code?

    Yes, I know added it later. There is strange thing, I think the snake is moving too fast, because when I add SDL_Delay(20) after snake.update() there is snake, but after around 5 seconds it blinks and there is not snake..Maybe I should try making snake to move slower or there is something that I should add for frames?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!