Jump to content
  • Advertisement

Dark Engineer

Member
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

132 Neutral

About Dark Engineer

  • Rank
    Member
  1. Dark Engineer

    How to use glfwSetKeyCallback?

    It doesn't show errors but if i want to put this cameraInstance to the Camera class and my class is used by one another class then shows 1>main.obj : error LNK2005: "class Camera * cameraInstance" (?cameraInstance@@3PAVCamera@@A) already defined in Camera.obj 1>Pipeline.obj : error LNK2005: "class Camera * cameraInstance" (?cameraInstance@@3PAVCamera@@A) already defined in Camera.obj 1> fatal error LNK1169: one or more multiply defined symbols found
  2. Dark Engineer

    How to use glfwSetKeyCallback?

    This glfwSetKeyCallback(Camera::keyWrapper);   don't work error C2664: 'glfwSetKeyCallback' : cannot convert parameter 1 from 'bool (__cdecl *)(int)' to 'GLFWkeyfun' 1>          None of the functions with this name in scope match the target type
  3. I have this function bool Camera::onKeyboard( int Key ) { bool Ret = false; switch (Key) { case GLFW_KEY_UP: { m_pos += (m_target * STEP_SCALE ); Ret = true; } break; case GLFW_KEY_DOWN: { m_pos -= (m_target * STEP_SCALE ); Ret = true; } break; case GLFW_KEY_LEFT: { glm::vec3 left = glm::cross(m_target, m_up ); glm::normalize(left); left *= STEP_SCALE; m_pos += left; Ret = true; } break; case GLFW_KEY_RIGHT: { glm::vec3 right = glm::cross(m_up, m_target); glm::normalize(right); right *= STEP_SCALE; m_pos += right; Ret = true; } break; } return Ret; } Adn when i try to make function and run it void GLFWCALL Camera::keyWrapper(int Key) { onKeyboard(Key); } glfwSetKeyCallback(pGameCamera->keyWrapper); it doesn't work. Can someone help me how to do it correct?
  4. Dark Engineer

    [OpenGL] render mesh with shaders

    thanks for advice, i'm using this site but not from the beginning, i will try to study it again
  5. I have code where i initialize mesh: #ifndef Mesh_h #define Mesh_h #include "Texture.h" #include "Technique.h" #include <map> #include <vector> #include <GL/glew.h> #include <glm/glm.hpp> #include <list> #include <assimp/Importer.hpp> // C++ importer interface #include <assimp/scene.h> // Output data structure #include <assimp/postprocess.h> // Post processing flags struct Vertex { glm::vec3 m_pos; glm::vec2 m_tex; glm::vec3 m_normal; Vertex() {} Vertex(const glm::vec3& pos, const glm::vec2& tex, const glm::vec3& normal) { m_pos = pos; m_tex = tex; m_normal = normal; } }; class Mesh : public Technique { bool init(); bool initFromScene(const aiScene* pScene, const std::string &Filename); void initMesh(unsigned int index, const aiMesh* paiMesh); bool initMaterials(const aiScene* pScene, const std::string &Filename); void clear(); #define INVALID_MATERIAL 0xFFFFFFFF struct MeshEntry { MeshEntry(); ~MeshEntry(); void init(const std::vector<Vertex> & vertices, const std::vector<unsigned int> & indices); GLuint VB; GLuint IB; unsigned int numIndices; unsigned int materialIndex; }; GLint gSamplerLocation; GLint WVPLocation; std::vector <MeshEntry> m_Entries; std::vector <Texture*> m_Textures; public: Mesh(); ~Mesh(); bool loadMesh(const std::string &filename); void render(); }; #endif #include "Mesh.h" Mesh::Mesh() { } Mesh::~Mesh() { clear(); } void Mesh::clear() { for(unsigned int i = 0; i < m_Textures.size(); i++) delete m_Textures; } Mesh::MeshEntry::MeshEntry() { VB = GL_INVALID_ENUM; IB = GL_INVALID_ENUM; numIndices = 0; materialIndex = INVALID_MATERIAL; } Mesh::MeshEntry::~MeshEntry() { if(VB != GL_INVALID_ENUM) glDeleteBuffers(1, &VB); if(IB != GL_INVALID_ENUM) glDeleteBuffers(1, &IB); } void Mesh::MeshEntry::init(const std::vector<Vertex> & vertices, const std::vector<unsigned int> & indices) { numIndices = indices.size(); glGenBuffers(1, &VB); glBindBuffer(GL_ARRAY_BUFFER, VB); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), &vertices[0], GL_STATIC_DRAW); glGenBuffers(1, &IB); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * numIndices, &indices[0], GL_STATIC_DRAW); } bool Mesh::loadMesh(const std::string & filename) { clear(); bool Ret = false; Assimp::Importer importer; const aiScene* pScene = importer.ReadFile(filename.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs); if(pScene) Ret = initFromScene(pScene, filename); else std::cout << "Error passing " << filename << " : " << importer.GetErrorString() << std::endl; return Ret; } bool Mesh::init() { if(!Technique::init()) return false; if(!addShader(Shader::VERTEX_SHADER, "vs.glsl")) return false; if(!addShader(Shader::FRAGMENT_SHADER, "fs.glsl")) return false; if(!finalize()) return false; gSamplerLocation = getUniformLocation("gSampler"); WVPLocation = getUniformLocation("gWVP"); if(gSamplerLocation == 0xFFFFFFFF || WVPLocation == 0xFFFFFFFF) return false; return true; } bool Mesh::initFromScene(const aiScene* pScene, const std::string &filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); for(unsigned int i = 0; i < m_Entries.size(); i++) { const aiMesh* paiMesh = pScene->mMeshes; initMesh(i, paiMesh); } return initMaterials(pScene, filename); } void Mesh::initMesh(unsigned int index, const aiMesh* paiMesh) { if(!init()) std::cout << "Failed to initialize shaders" << std::endl; m_Entries[index].materialIndex = paiMesh->mMaterialIndex; std::vector <Vertex> vertices; std::vector <unsigned int> indices; const aiVector3D zero3D(0.0f, 0.0f, 0.0f); for(unsigned int i = 0; i < paiMesh->mNumVertices; i++) { const aiVector3D * pPos = &(paiMesh->mVertices); const aiVector3D *pNormal = &(paiMesh->mNormals); const aiVector3D *pTextCoord = paiMesh->HasTextureCoords(0) ? &(paiMesh->mTextureCoords[0]) : &zero3D; Vertex v(glm::vec3(pPos->x, pPos->y, pPos->z), glm::vec2(pTextCoord->x, pTextCoord->y), glm::vec3(pNormal->x, pNormal->y, pNormal->z)); vertices.push_back(v); } for(unsigned int i = 0; i < paiMesh->mNumFaces; i++) { const aiFace &face = paiMesh->mFaces; indices.push_back(face.mIndices[0]); indices.push_back(face.mIndices[1]); indices.push_back(face.mIndices[2]); } m_Entries[index].init(vertices, indices); } bool Mesh::initMaterials(const aiScene* pScene, const std::string &filename) { std::string::size_type SlashIndex = filename.find_last_of("/"); std::string Dir; if (SlashIndex == std::string::npos) { Dir = "."; } else if (SlashIndex == 0) { Dir = "/"; } else { Dir = filename.substr(0, SlashIndex); } bool Ret = true; for(unsigned int i = 0; i < pScene->mNumMaterials; i++) { const aiMaterial *pMaterial = pScene->mMaterials; m_Textures = NULL; if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) { aiString path; if(pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { std::string fullPath = Dir + "/" + path.data; m_Textures = new Texture(GL_TEXTURE_2D, path.C_Str()); if(!m_Textures->Load()) { std::cout << "Error Loading texture " << path.C_Str() << std::endl; delete m_Textures; m_Textures = NULL; Ret = false; } else std::cout << "Loaded texture " << path.C_Str() << std::endl; } } if(!m_Textures) { std::cout << "No textures" << std::endl; m_Textures = new Texture(GL_TEXTURE_2D, "/white.png"); Ret = m_Textures->Load(); } } return Ret; } void Mesh::render() { glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); for(unsigned int i = 0; i < m_Entries.size(); i++) { glBindBuffer(GL_ARRAY_BUFFER, m_Entries.VB); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Entries.IB); const unsigned int materialIndex = m_Entries.materialIndex; if( materialIndex < m_Textures.size() && m_Textures[materialIndex]) { m_Textures[materialIndex]->Bind(GL_TEXTURE0); } glDrawElements(GL_TRIANGLES, m_Entries.numIndices, GL_UNSIGNED_INT, 0); } glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); } but when i try to render it with this methods in render() function it doesn't work, how can i change this code to get it working? Can i make shaders and use it? Edit// On the screen i see only white color? What to do?
  6. Dark Engineer

    OpenGL mesh with light

    My mesh wasn't work properly so i was thinking that is because i don't have lights
  7. Dark Engineer

    OpenGL mesh with light

    I wrote code for mesh and light but when i'm trying to see this things they don't show. On the screen i see only black color nothing else My code is here https://github.com/DarkEngineer/Crion-World
  8. Dark Engineer

    OpenGL triangle example

    Solved it just needed to change in loop GLFW_WINDOW to GLFW_OPENED
  9. Dark Engineer

    OpenGL triangle example

    I have in console and logs that both shaders loaded successfully and program loaded successfully but still have this same error. Maybe i made something wrong with creating window.
  10. Dark Engineer

    OpenGL triangle example

    SimpleFragmentShader #version 150 out vec4 outColor; void main() {     outColor = vec4( 1.0, 1.0, 1.0, 1.0 ); } SimpleVertexShader #version 150 in vec2 position; void main() {     gl_Position = vec4( position, 0.0, 1.0 ); } and function for loading them string loadShaderFile(const string fileName) {          ifstream shaderFile( fileName.c_str());     //find the file size     shaderFile.seekg(0, ios::end);     std::streampos length = shaderFile.tellg();     shaderFile.seekg(0, ios::beg);     //read whole file into a vector     vector<char> buffer(length);     shaderFile.read(&buffer[0], length);     //return the shader string     return string( buffer.begin(), buffer.end()); } I think something is wrong under 53 line but i'm begginer in OpenGL
  11. Dark Engineer

    OpenGL triangle example

    It doesn't change anything. When i turn application on then debug error appears with Invalid allocation size: 4294967295 bytes
  12. I have problem with this code because it doesn't show anything in a window, vertex and fragment shaders are loading successfully but glGetError shows something wrong is here. Please someone help me. #include "loadshader.h" int main() { glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); glfwOpenWindow(800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW); glfwSetWindowTitle("Crion World Alpha"); glewExperimental = GL_TRUE; glewInit(); GLuint vertexBuffer; glGenBuffers( 1, &vertexBuffer ); GLuint vao; glGenVertexArrays(1, & vao); glBindVertexArray( vao ); GLuint vbo; glGenBuffers( 1, &vbo); //generate 1 buffer float vertices[] = { 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f }; glBindBuffer( GL_ARRAY_BUFFER, vbo ); glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW ); // vertex shader loading const string vShaderString = loadShaderFile("SimpleVertexShader.vertexshader").c_str(); const GLchar * tempVShader = vShaderString.c_str(); GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER ); glShaderSource(vertexShader, 1, & tempVShader, NULL); glCompileShader( vertexShader ); std::fstream logs; logs.open( "logs.txt", ios::in | ios::out | ios::trunc ); char vsbuffer[512]; glGetShaderInfoLog( vertexShader, 512, NULL, vsbuffer ); logs << vsbuffer; //fragment shader loading const string fShaderString = loadShaderFile("SimpleFragmentShader.fragmentshader").c_str(); const GLchar * tempFShader = fShaderString.c_str(); GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); glShaderSource(fragmentShader, 1, & tempFShader, NULL ); glCompileShader(fragmentShader); char fsbuffer[512]; glGetShaderInfoLog( fragmentShader, 512, NULL, fsbuffer ); logs << fsbuffer; if(glGetError() != 0) { logs << "sth errors"; cout << "sth wrong" << endl; } logs.close(); GLuint shaderProgram = glCreateProgram(); glAttachShader( shaderProgram, vertexShader ); glAttachShader( shaderProgram, fragmentShader); glBindFragDataLocation( shaderProgram, 0, "outColor" ); glLinkProgram( shaderProgram ); glUseProgram( shaderProgram ); GLint posAttrib = glGetAttribLocation( shaderProgram, "position" ); glEnableVertexAttribArray( posAttrib ); glVertexAttribPointer( posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0 ); while( glfwGetWindowParam( GLFW_WINDOW ) ) { glDrawArrays( GL_TRIANGLES, 0, 3); glfwSwapBuffers(); } glDeleteProgram( shaderProgram ); glDeleteShader( vertexShader ); glDeleteShader( fragmentShader ); glDeleteBuffers(1, & vbo ); glDeleteVertexArrays(1, &vao ); glfwTerminate(); return 0; }
  13. Dark Engineer

    GLSL not working

    Thanks
  14. Dark Engineer

    GLSL not working

    I don't know how to create glsl object
  15. Dark Engineer

    OpenGL GLSL not working

    I have problem with glsl on windows 8 in Microsoft Visual Studio Express 2012 with Radeon. Even #version 150 is not recognized in code.   #version 150 #include <glm\ext.hpp> #include <glm\glm.hpp> #include <GL\glew.h> #include <GL\glut.h> #include <GL\GL.h> #include <GL\GLU.h> #include <GL\glfw.h> in vec2 position; out vec4 outColor; int main() { vec3 commeo; glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); glfwOpenWindow(800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW); glfwSetWindowTitle("Crion World Alpha"); while( glfwGetWindowParam( GLFW_WINDOW ) ) { glfwSwapBuffers(); } if( glfwGetKey( GLFW_KEY_ESC ) == GLFW_PRESS ) return 0; glewExperimental = GL_TRUE; glewInit(); GLuint vertexBuffer; glGenBuffers( 1, &vertexBuffer ); printf( "%u\n", vertexBuffer); float vertices[] = { 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f }; GLuint vbo; glGenBuffers( 1, &vbo); //generate 1 buffer glBindBuffer( GL_ARRAY_BUFFER, vbo ); glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW ); GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER ); glShaderSource( vertexShader, 1, &vertexSource, NULL ); glCompileShader( vertexShader ); glfwTerminate(); return 0; } I have errors:   1 IntelliSense: unrecognized preprocessing directive /// #version 150 2 IntelliSense: identifier "in" is undefined 4 IntelliSense: identifier "out" is undefined 6 IntelliSense: identifier "vec3" is undefined 7 IntelliSense: identifier "vertexSource" is undefined I have linked: opengl32.lib glu32.lib glut32.lib glfwdll.lib glew32d.lib
  • 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!