• What do you need help with? Version 5
    5,752 replies, posted
I need help understanding the OpenGL perspective matrix. The OpenGL superbible just uses the GLTools library and never seems to explain it (the one thing I hated about that book). I need a basic understanding and an ability to construct one, including what values to use for given FOV and resolution, aspect ratio, etc. Searching around on google has led me to nothing more than depricated function calls and third party library forum issues (like everything else in OpenGL -_- (with the exception of the now amazing Open.gl of course)).
[QUOTE=flayne;36446355]I need help understanding the OpenGL perspective matrix. The OpenGL superbible just uses the GLTools library and never seems to explain it (the one thing I hated about that book). I need a basic understanding and an ability to construct one, including what values to use for given FOV and resolution, aspect ratio, etc. Searching around on google has led me to nothing more than depricated function calls and third party library forum issues (like everything else in OpenGL -_- (with the exception of the now amazing Open.gl of course)).[/QUOTE] [url]http://www.songho.ca/opengl/gl_projectionmatrix.html[/url] That'll tell you everything you need to know about the old glFrustum() type matrix. If you want define your projection using FOV and aspect ratio, then you can obtain the clip plane values with some basic trig: near and far: self-explanitory top and bottom: +/- near * sin(fov) left and right: +/- near * aspectratio * sin(fov) ...Assuming 'FOV' is the [i]vertical[/i] FOV, which is the convention that GLU and GLM use.
[QUOTE=conman420;36445379]Has anyone here used Mini-XML? I'm trying to load a pretty simple XML file and then set attributes to a class from it but I keep getting memory errors and I am not sure what's going on: [cpp] #include "XMLParser.h" FILE* XMLParser::mFile; mxml_node_t* XMLParser::mTree; ModelData XMLParser::CurrentModel; void XMLParser::LoadFile(const char* path) { mFile = std::fopen(path, "r"); mTree = mxmlLoadFile(NULL, mFile, LoadCallBack); fclose(mFile); mxml_node_t* next_node = mTree; while (next_node != NULL) { std::string type(mxmlGetElement(next_node)); std::cout << type << "\n"; next_node = mxmlWalkNext(next_node, mTree, MXML_DESCEND); } std::cout << "Finished Loading Model:" << "\n"; std::cout << "Texture Path: " << CurrentModel.mTexturePath << "\n"; std::cout << "Density: " << CurrentModel.mDensity << "\n"; std::cout << "Vertex Count: " << CurrentModel.mVertexCount << "\n"; } mxml_type_t XMLParser::LoadCallBack(mxml_node_t *node) { std::string type(mxmlGetElement(node)); //Troll Code //std::cout << ":" << type << ":\n"; if (type == "texture") { return MXML_TEXT; } else if (type == "density") { return MXML_REAL; } else if (type == "vertex") { return MXML_TEXT; } return MXML_TEXT; } /* <model> <physics_hull> <texture>images/crate</texture> <density>4</density> <vertex_count>4</vertex_count> <vertices> <vertex>50 50</vertex> <vertex>-50 50</vertex> <vertex>-50 -50</vertex> <vertex>50 -50</vertex> </vertices> </physics_hull> </model> [/cpp] At the bottom is the XML file I am trying to parse. The program crashes when trying to access mxmlGetElement(node) I'm not really sure how to use this library to be honest the documentation is pretty sparse.[/QUOTE] idk that lib but tinyxml is really easy to use and works pretty well too maybe give it a shot?
Opera allows the user to add items to the context menu. You can use the command "Go to page" along with the javascript URI to run any javascript code. My question is; what is a good way to get the element under the cursor? activeElement works for some but not all elements.
Can anyone critique [url=http://pastie.org/4136173]this BubbleSort demo[/url] and if there are any more optimizations I can add to it apart from "use quicksort". It currently runs in about 9.544s
Hey guys, I'm currently working on Overv's openGL tutorial but when I run his drawing section's [URL="http://open.gl/content/code/c2_triangle_elements.txt"]source code[/URL] I get these annoying errors: 1>main.obj : error LNK2001: unresolved external symbol ___glewDeleteVertexArrays 1>main.obj : error LNK2001: unresolved external symbol ___glewBindFragDataLocation 1>main.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray 1>main.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays When I comment them out, the program works fine. Still, any help?
[QUOTE=HyperVyper;36451903]Hey guys, I'm currently working on Overv's openGL tutorial but when I run his drawing section's [URL="http://open.gl/content/code/c2_triangle_elements.txt"]source code[/URL] I get these annoying errors: 1>main.obj : error LNK2001: unresolved external symbol ___glewDeleteVertexArrays 1>main.obj : error LNK2001: unresolved external symbol ___glewBindFragDataLocation 1>main.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray 1>main.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays When I comment them out, the program works fine. Still, any help?[/QUOTE] You need to link to the glew library. In linux you just compile with the -lglew flag, but I can't quite remember how to do it in windows. All I remember is that it was hell to do so. Good luck. :u
[QUOTE=Naelstrom;36451961]You need to link to the glew library. In linux you just compile with the -lglew flag, but I can't quite remember how to do it in windows. All I remember is that it was hell to do so. Good luck. :u[/QUOTE] Depends which Windows IDE/compiler you're using. If you're using a sane one like Code::Blocks/MinGW, you also just add -lglew. If, on the other hand, you're using Visual Studio, godspeed and may heaven have mercy on your soul.
[QUOTE=HyperVyper;36451903]Hey guys, I'm currently working on Overv's openGL tutorial but when I run his drawing section's [URL="http://open.gl/content/code/c2_triangle_elements.txt"]source code[/URL] I get these annoying errors: 1>main.obj : error LNK2001: unresolved external symbol ___glewDeleteVertexArrays 1>main.obj : error LNK2001: unresolved external symbol ___glewBindFragDataLocation 1>main.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray 1>main.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays When I comment them out, the program works fine. Still, any help?[/QUOTE] gotta link glfw if youre using visual studio its like #pragma comment(lib, "glew.lib") or something [editline]23rd June 2012[/editline] #pragma comment(lib, "glew32.lib") and make sure you have glew in your library path
My friend is using Norton antivirus, and I have tried compiling my C++ program in Dev-C++ and Code::Blocks and both of them make him detect my application as a virus and automatically remove it. What is baffling about this, is that I barely even know C++ and my code is extremely simple. I just wanted to send him the .exe to see if he could run it. I did an online scan, and 1/20 anti virusus detected it (forgot which one, it was a weird one) norton wasn't on the list though. [url]http://pastebin.com/HttT4pid[/url] That's the entire code, all in main.cpp Any help would be great. Just curious as to why my simple c++ experiments are harboring virusus serious enough to need automatic deletion.
Have you tried a simple hello world program? Or compiling on an another machine? If the antivirus doesn't complain about hello world it may be file system requests. Then you would only have to comment some lines one by one to pinpoint a cause. Also, I recommend you not to use dev-c++ it's pretty dead and it's libraries and headers are quite old. You can compare them to code::blocks' ones
[QUOTE=usa;36451502]Can anyone critique [url=http://pastie.org/4136173]this BubbleSort demo[/url] and if there are any more optimizations I can add to it apart from "use quicksort". It currently runs in about 9.544s[/QUOTE] Not necessarily an optimization, but you're hardcoding the size of the array in the completion percent mechanism at the same time as you're passing it in for another part of the algorithm. Pick one.
[QUOTE=HyperVyper;36451903]Hey guys, I'm currently working on Overv's openGL tutorial but when I run his drawing section's [URL="http://open.gl/content/code/c2_triangle_elements.txt"]source code[/URL] I get these annoying errors: 1>main.obj : error LNK2001: unresolved external symbol ___glewDeleteVertexArrays 1>main.obj : error LNK2001: unresolved external symbol ___glewBindFragDataLocation 1>main.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray 1>main.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays When I comment them out, the program works fine. Still, any help?[/QUOTE] Link with [i]glew32s.lib[/i] and make sure to [i]#define GLEW_STATIC[/i] [b]before[/b] including GLEW.
Anyone know why this is refusing to compile? I am forward declaring BaseObject in the header and then including it properly in the .cpp file but it just errors out with: 1>c:\users\connor\documents\programming\projects\ose\ose\engine\Camera.h(9): error C2146: syntax error : missing ';' before identifier 'mTargetPos' No idea why I've done this kind of thing on all my other headers: [cpp] #pragma once class BaseObject; class sCamera { private: static BaseObject* mTarget; static Vector2 mTargetPos; static float mDamping; static float mFollowSpeed; static bool mIsFollowing; static float mRot; static float mZoom; static float mTargetZoom; static float mZoomDamping; static Vector2 mCentre; public: static void SetZoom(float z) {mTargetZoom = z;}; static float GetZoom() {return mZoom;}; static void SetZoomDamping(float z) {mZoomDamping = z;}; static float GetZoomDamping() {return mZoomDamping;}; static void ReSize(Vector2 Size); static void SetCentre(Vector2 &pos) {mCentre = pos;}; static Vector2 GetCentre() {return mCentre;}; static void SetRotation(float rot) {mRot = rot;}; static float GetRotation() {return mRot;}; static void Rotate(float amount) {SetRotation(GetRotation() + amount);}; static void FollowEntity(BaseObject* ent) {mTarget=ent; mIsFollowing = true;}; static bool IsFollowing() {return mIsFollowing;}; static void SetDamping(float damp) {mDamping = damp;}; static float GetDamping() {return mDamping;}; static void UpdateView(); }; [/cpp] This is how I include everything in Camera.cpp: [cpp] #include "Camera.h" #include "GameGlobals.h" #include "Bases/BaseObject.h" BaseObject* sCamera::mTarget; Vector2 sCamera::mTargetPos; float sCamera::mDamping; float sCamera::mFollowSpeed; bool sCamera::mIsFollowing; float sCamera::mRot; float sCamera::mZoom; float sCamera::mTargetZoom; float sCamera::mZoomDamping; Vector2 sCamera::mCentre; [/cpp]
Kinda on topic; why do people find it so hard to link with stuff in Visual Studio? You just add the name of the lib file to the Linker > Inputs section of your project properties for the build configurations you want it to link on... If the library is in a non-standard directory then you add that to the relevant part of the 'VC++ Directories' section. It's not [I]that[/I] difficult.
[QUOTE=conman420;36456405]Anyone know why this is refusing to compile? I am forward declaring BaseObject in the header and then including it properly in the .cpp file but it just errors out with: 1>c:\users\connor\documents\programming\projects\ose\ose\engine\Camera.h(9): error C2146: syntax error : missing ';' before identifier 'mTargetPos' No idea why I've done this kind of thing on all my other headers: [/QUOTE] Based on the position of the error, it looks like a problem with the "Vector2" type. Where/how is that declared?
[quote=Faggot visual c++] error LNK2019: unresolved external symbol "class GraphicsMan __cdecl Rendering(void)" (?Rendering@@YA?AVGraphicsMan@@XZ) referenced in function "int __cdecl Load(void)" (?Load@@YAHXZ) D:\Documents and Settings\Fuck\My Documents\Visual Studio 2008\Projects\SS32\Debug\SSX.exe : fatal error LNK1120: 1 unresolved externals [/quote] I've been trying to fix this damn Linker error for four hours now. [img]http://s7.postimage.org/jx1sl3k4b/linked.png[/img] As you can see I have everything linked though. Here's some code that might help: GraphicsMan.h - Graphics Manager class. [cpp] class GraphicsMan { private: sf::Image ImageBox[64]; //Images go here sf::Sprite SpriteBox[64]; //Sprites go here sf::Sprite RenderBox[64]; //Sprites to draw go here int counter; public: GraphicsMan(); GraphicsMan(sf::Image images[64]); void LoadImages(sf::Image images[64]); //Load images into ImageBox }; [/cpp] GraphicsMan.cpp - LoadImage function: [cpp] void GraphicsMan::LoadImages(sf::Image images[64]) { //Because a simple array[] = array[] doesn't work. Asshole. for (int i=0;i<64;i++) { GraphicsMan::ImageBox[i] = images[i]; } } [/cpp] Main file.cpp - How I'm using it: [cpp] GraphicsMan Rendering(); int Load() { sf::Image Images[64]; //Make an image array Images[0].LoadFromFile("test.PNG"); //Put a single image in the first slot. Rendering().LoadImages(Images); //Now load that shit. return 1; } [/cpp] What the hell did I break? [editline]23rd June 2012[/editline] Could be some minor mistakes in there due to me having to rename my variables to something more SFW.
[QUOTE=Chris220;36456632]Kinda on topic; why do people find it so hard to link with stuff in Visual Studio? You just add the name of the lib file to the Linker > Inputs section of your project properties for the build configurations you want it to link on... If the library is in a non-standard directory then you add that to the relevant part of the 'VC++ Directories' section. It's not [I]that[/I] difficult.[/QUOTE] It's basically the same difficulty as Code::Blocks.
[QUOTE=Anthos;36457380]I've been trying to fix this damn Linker error for four hours now. [img]http://s7.postimage.org/jx1sl3k4b/linked.png[/img] As you can see I have everything linked though. Here's some code that might help: Could be some minor mistakes in there due to me having to rename my variables to something more SFW.[/QUOTE] you need to link graphics then window then system in that order.
[QUOTE=Richy19;36457561]you need to link graphics then window then system in that order.[/QUOTE] Nope, sorry. Same error. [editline]23rd June 2012[/editline] I stand corrected: [quote] Error 1 error LNK2019: unresolved external symbol "class GraphicsMan __cdecl Renderer(void)" (?Renderer@@YA?AVGraphicsMan@@XZ) referenced in function "int __cdecl Load(void)" (?Load@@YAHXZ) SSX.obj [/quote] ...Wha.
Im trying to be able to have multiple images in a shader with non deprecated(and glsl 120), frag shader being: [cpp] #version 120 uniform sampler2D TEXTURE0; uniform sampler2D TEXTURE1; uniform sampler2D TEXTURE2; uniform sampler2D TEXTURE3; uniform sampler2D TEXTURE4; uniform sampler2D TEXTURE5; uniform sampler2D TEXTURE6; varying vec4 position; varying vec2 uv; varying vec3 normal; varying float imageindex; void main() { vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f); if(((int)imageindex) == 0) color = texture2D(TEXTURE0, uv); if(((int)imageindex) == 1) color = texture2D(TEXTURE1, uv); if(((int)imageindex) == 2) color = texture2D(TEXTURE2, uv); if(((int)imageindex) == 3) color = texture2D(TEXTURE3, uv); if(((int)imageindex) == 4) color = texture2D(TEXTURE4, uv); if(((int)imageindex) == 5) color = texture2D(TEXTURE5, uv); if(((int)imageindex) == 6) color = texture2D(TEXTURE6, uv); gl_FragColor = color; }[/cpp] But I keep getting this error: [QUOTE]0:19(10): error: syntax error, unexpected ')', expecting '(' [/QUOTE]
I'm still having trouble with OpenGL blending and framebuffers. If anyone wants to help, I've made a question on StackOverflow and made a git-repository for it. [url]http://stackoverflow.com/questions/11083333[/url] [url]https://github.com/Landeplage/Amigo[/url]
[QUOTE=Naelstrom;36451961]You need to link to the glew library. In linux you just compile with the -lglew flag, but I can't quite remember how to do it in windows. All I remember is that it was hell to do so. Good luck. :u[/QUOTE] If you're using G++ you use the -lglew flag :P.
I have this frag shader: [cpp] #version 120 uniform sampler2D TEXTURE0; uniform sampler2D TEXTURE1; uniform sampler2D TEXTURE2; uniform sampler2D TEXTURE3; uniform sampler2D TEXTURE4; uniform sampler2D TEXTURE5; uniform sampler2D TEXTURE6; varying vec4 position; varying vec2 uv; varying vec3 normal; varying float imageindex; void main() { vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f); if(int(imageindex) == 0) color = texture2D(TEXTURE0, uv); if(int(imageindex) == 1) color = texture2D(TEXTURE1, uv); if(int(imageindex) == 2) color = texture2D(TEXTURE2, uv); if(int(imageindex) == 3) color = texture2D(TEXTURE3, uv); if(int(imageindex) == 4) color = texture2D(TEXTURE4, uv); if(int(imageindex) == 5) color = texture2D(TEXTURE5, uv); if(int(imageindex) == 6) color = texture2D(TEXTURE6, uv); gl_FragColor = color; } [/cpp] And I create the images and send them to the gpu like this: [cpp] SOGLF::Texture bitmap; bitmap.LoadFromFile("./Resources/"+mimg); bitmaps.push_back(bitmap); [/cpp] and [cpp] for(int i = 0; i < bitmaps.size(); i++ ) { glActiveTexture(GL_TEXTURE0 + i); bitmaps[i].Bind(); std::string textureName = "TEXTURE"; textureName += SOGLF::Util::toString(i); glUniform1i( shader.GetUniform(textureName.c_str()) , i); } [/cpp] Im not getting any openGL errors however "color" gets turned into black. Anything im missing?
[QUOTE=flayne;36458832]If you're using G++ you use the -lglew flag :P.[/QUOTE] Sorry, I guess I meant Visual studio c++. I wanted to gain some converts so I generalized windows. Which by the way, if you're still using windows and have never tried a development environment like Linux, I highly recommend it. :v: [QUOTE=Mordi;36458424]I'm still having trouble with OpenGL blending and framebuffers. If anyone wants to help, I've made a question on StackOverflow and made a git-repository for it. [url]http://stackoverflow.com/questions/11083333[/url] [url]https://github.com/Landeplage/Amigo[/url][/QUOTE] Do you have blending enabled when you clear the fbo? Sounds like opengl is blending glClearColor(0.0, 0.0, 0.0, 0.0); and none of it is reaching the buffer (because it has 0 alpha). You probably want to check if the frame buffer was successfully created as well using [url=http://www.opengl.org/sdk/docs/man3/xhtml/glCheckFramebufferStatus.xml]glCheckFramebufferStatus[/url] That's all I can think of looking at your code. You're doing lots of weird stuff, but I can't say that's wrong. Feel free to add me on steam if you want to chat. I have a bit of experience with FBO's from the [url=http://bit.ly/LqcaxX]lighting system in my game.[/url]
I got it partially working but the image selection isnt working right. I made a simple example: [cpp] #include "./Program.hpp" #include <iostream> Program::Program() { //Set window settings } Program::~Program() { glDeleteBuffers(4, buffers); for(int i = 0; i < bitmaps.size(); i++ ) { delete bitmaps[i]; } } bool Program::Initialize() { //Initialize base class at start to create window bool initBaseResult = BaseProgram::Initialize(); //Init some stuff here //glEnable(GL_CULL_FACE); // glEnable(GL_DEPTH_TEST); // glEnable (GL_BLEND); // glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); shader.LoadShaderFiles("./basic.vert" , "./basic.frag"); /* #version 120 uniform mat4 Model; uniform mat4 MVP; uniform mat4 View; attribute vec3 Position; attribute vec3 Normals; attribute vec2 UV; attribute float ImageIndex; varying vec4 position; varying vec2 uv; varying vec3 normal; varying float imageindex; void main() { imageindex = ImageIndex; normal = normalize( (View * Model * vec4(Normals, 0.0f)).xyz ); uv = UV; position = MVP * vec4(Position,1.0); gl_Position = position; } */ /* #version 120 uniform sampler2D TEXTURE0; uniform sampler2D TEXTURE1; uniform sampler2D TEXTURE2; uniform sampler2D TEXTURE3; uniform sampler2D TEXTURE4; uniform sampler2D TEXTURE5; varying vec4 position; varying vec2 uv; varying vec3 normal; varying float imageindex; void main() { int index = int(imageindex); vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f); if(index == 0) color = texture2D(TEXTURE0, uv); if(index == 1) color = texture2D(TEXTURE1, uv); if(index == 2) color = texture2D(TEXTURE2, uv); if(index == 3) color = texture2D(TEXTURE3, uv); if(index == 4) color = texture2D(TEXTURE4, uv); if(index == 5) color = texture2D(TEXTURE5, uv); gl_FragColor = color; } */ glm::mat4 pos = glm::translate(glm::mat4(1.0f), 0.0f, 0.0f, -5.0f); glm::mat4 ang = glm::rotate(glm::mat4(1.0f),-90.0f,glm::vec3(0,0,1)); ang = glm::rotate(ang, -90.0f,glm::vec3(0,1,0)); ang = glm::rotate(ang, 0.0f,glm::vec3(1,0,0)); glm::mat4 sca = glm::scale(glm::mat4(1.0f),1.0f, 1.0f,1.0f); model = pos*ang*sca; glGenBuffers(4, buffers); return initBaseResult; } bool Program::LoadContent() { //Load content here for(int i = 0; i<5; i++) { PosList.push_back(glm::vec3( 0 + i, 0, -1)); PosList.push_back(glm::vec3( 0 + i, 1, -1)); PosList.push_back(glm::vec3( 1 + i, 0, -1)); PosList.push_back(glm::vec3( 1 + i, 0, -1)); PosList.push_back(glm::vec3( 0 + i, 1, -1)); PosList.push_back(glm::vec3( 1 + i, 1, -1)); UVList.push_back(glm::vec2(0,0)); UVList.push_back(glm::vec2(0,1)); UVList.push_back(glm::vec2(1,0)); UVList.push_back(glm::vec2(1,0)); UVList.push_back(glm::vec2(0,1)); UVList.push_back(glm::vec2(1,1)); int b = 0; if((i % 2) == 0) b = 1; ImageIndexList.push_back(b); ImageIndexList.push_back(b); ImageIndexList.push_back(b); ImageIndexList.push_back(b); ImageIndexList.push_back(b); ImageIndexList.push_back(b); } SOGLF::Texture *bitmap = new SOGLF::Texture(); bitmap->LoadFromFile("./4141.jpg"); bitmaps.push_back(bitmap); SOGLF::Texture *bitmap2 = new SOGLF::Texture(); bitmap2->LoadFromFile("./4242.jpg"); bitmaps.push_back(bitmap2); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, PosList.size() * sizeof(glm::vec3), &PosList[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glBufferData(GL_ARRAY_BUFFER, UVList.size() * sizeof(glm::vec2), &UVList[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buffers[2]); glBufferData(GL_ARRAY_BUFFER, NormList.size() * sizeof(glm::vec3), &NormList[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buffers[3]); glBufferData(GL_ARRAY_BUFFER, ImageIndexList.size() * sizeof(unsigned char), &ImageIndexList[0], GL_STATIC_DRAW); return true; } void Program::Update() { //Update stuff here if(SOGLF::Keyboard::IsKeyDown(SOGLF::Keyboard::Escape)) SOGLF::WindowClass::Window.Close(); if(SOGLF::Keyboard::IsKeyDown(SOGLF::Keyboard::F1)) { std::string file = SOGLF::Util::CurrentDate().str(); SOGLF::WindowClass::Window.Capture("blah_" + file + "_.bmp"); } } void Program::Draw() { SOGLF::WindowClass::Window.Clear(); //Draw stuff here const glm::mat4 &c = SOGLF::Matrices::Matrix.Camera; MVP = SOGLF::Matrices::Matrix.GetProjection() *c* model; shader.Bind(); glUniformMatrix4fv( shader.GetUniform("MVP") , 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv( shader.GetUniform("Model") , 1, GL_FALSE, &model[0][0]); glUniformMatrix4fv( shader.GetUniform("View") , 1, GL_FALSE, &c[0][0]); for(int i = 0; i < bitmaps.size(); i++ ) { glActiveTexture(GL_TEXTURE0 + i); bitmaps[i]->Bind(); std::string textureName = "TEXTURE"; textureName += SOGLF::Util::toString(i); glUniform1i( shader.GetUniform(textureName.c_str()) , i); } glEnableVertexAttribArray( shader.GetAttribute("ImageIndex") ); glBindBuffer(GL_ARRAY_BUFFER, buffers[3]); glVertexAttribPointer( shader.GetAttribute("ImageIndex"), // attribute 0. No particular reason for 0, but must match the layout in the shader. 1, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glEnableVertexAttribArray( shader.GetAttribute("Position") ); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glVertexAttribPointer( shader.GetAttribute("Position"), // 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( shader.GetAttribute("UV") ); glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glVertexAttribPointer( shader.GetAttribute("UV"), // 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 ); glEnableVertexAttribArray(shader.GetAttribute("Normals")); glBindBuffer(GL_ARRAY_BUFFER, buffers[2]); glVertexAttribPointer( shader.GetAttribute("Normals"), // 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 ); // Index buffer glDrawArrays(GL_TRIANGLES, 0, PosList.size()); glDisableVertexAttribArray(shader.GetAttribute("Normals")); glDisableVertexAttribArray(shader.GetAttribute("UV")); glDisableVertexAttribArray(shader.GetAttribute("Position")); glDisableVertexAttribArray(shader.GetAttribute("ImageIndex")); SOGLF::Texture::Unbind(); SOGLF::Shader::Unbind(); SOGLF::WindowClass::Window.Display(); GLenum errCode; const GLubyte *errString; if ((errCode = glGetError()) != GL_NO_ERROR) { errString = gluErrorString(errCode); std::cout << "OpenGL Error: " << errString << std::endl; } } [/cpp] [IMG]http://i.imgur.com/mNnNq.png[/IMG]
[QUOTE=ShaunOfTheLive;36456926]Based on the position of the error, it looks like a problem with the "Vector2" type. Where/how is that declared?[/QUOTE] It isn't the vector2 type, I managed to get it compiling by swapping the order of includes in Camera.cpp to: [cpp] #include "Bases/BaseObject.h" #include "Camera.h" #include "GameGlobals.h" [/cpp] Although I am curious to know why this worked, and I don't like this solution it seems hacky.
[QUOTE=Richy19;36459755]I have this frag shader: [cpp] #version 120 uniform sampler2D TEXTURE0; uniform sampler2D TEXTURE1; uniform sampler2D TEXTURE2; uniform sampler2D TEXTURE3; uniform sampler2D TEXTURE4; uniform sampler2D TEXTURE5; uniform sampler2D TEXTURE6; varying vec4 position; varying vec2 uv; varying vec3 normal; varying float imageindex; void main() { vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f); if(int(imageindex) == 0) color = texture2D(TEXTURE0, uv); if(int(imageindex) == 1) color = texture2D(TEXTURE1, uv); if(int(imageindex) == 2) color = texture2D(TEXTURE2, uv); if(int(imageindex) == 3) color = texture2D(TEXTURE3, uv); if(int(imageindex) == 4) color = texture2D(TEXTURE4, uv); if(int(imageindex) == 5) color = texture2D(TEXTURE5, uv); if(int(imageindex) == 6) color = texture2D(TEXTURE6, uv); gl_FragColor = color; } [/cpp] And I create the images and send them to the gpu like this: [cpp] SOGLF::Texture bitmap; bitmap.LoadFromFile("./Resources/"+mimg); bitmaps.push_back(bitmap); [/cpp] and [cpp] for(int i = 0; i < bitmaps.size(); i++ ) { glActiveTexture(GL_TEXTURE0 + i); bitmaps[i].Bind(); std::string textureName = "TEXTURE"; textureName += SOGLF::Util::toString(i); glUniform1i( shader.GetUniform(textureName.c_str()) , i); } [/cpp] Im not getting any openGL errors however "color" gets turned into black. Anything im missing?[/QUOTE] My guess is that there's something wrong loading the texture or perhaps assigning it to a sampler since there are no other cases I can think of where the samplers return black. If you aren't sampling anything, the fragment should be white.
So I fixed the linker errors in my previous post but now these two guys have popped up, I'm getting the feeling my Visual studio might be broken or something because I never had any of these kind of linking problems before I downgraded to XP. Anyone that knows if I'm just doing something really stupid or it's just Visual C++ being a bitch? [quote] Error 2 error LNK2019: unresolved external symbol "private: class std::vector<class sf::Sprite,class std::allocator<class sf::Sprite> > __thiscall GraphicsMan::RenderBox(void)" (?RenderBox@GraphicsMan@@AAE?AV?$vector@VSprite@sf@@V?$allocator@VSprite@sf@@@std@@@std@@XZ) referenced in function "public: class sf::Sprite __thiscall [B]GraphicsMan::GiveRender(int)[/B]" (?GiveRender@GraphicsMan@@QAE?AVSprite@sf@@H@Z) Graphics.obj [/quote] [cpp] //Using this to loop through the renderbox and Draw() all sprites sf::Sprite GraphicsMan::GiveRender(int num) { return GraphicsMan::RenderBox().at(num); } [/cpp] [quote] Error 1 error LNK2019: unresolved external symbol "private: class std::vector<class sf::Image,class std::allocator<class sf::Image> > __thiscall GraphicsMan::ImageBox(void)" (?ImageBox@GraphicsMan@@AAE?AV?$vector@VImage@sf@@V?$allocator@VImage@sf@@@std@@@std@@XZ) referenced in function "public: class std::vector<int,class std::allocator<int> > __thiscall [B]GraphicsMan::LoadTileMap[/B](class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?LoadTileMap@GraphicsMan@@QAE?AV?$vector@HV?$allocator@H@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@H@Z) Graphics.obj [/quote] [cpp] //Turn a single image into a fuckload of sprites. std::vector<int> GraphicsMan::LoadTileMap(std::string imgloc,int size) { //Load the image into the first-available image slot int x = GraphicsMan::counter; GraphicsMan::ImageBox()[x].LoadFromFile(imgloc); //Define all variables int Size = size; int Height = GraphicsMan::ImageBox()[x].GetHeight(); int Width = GraphicsMan::ImageBox()[x].GetWidth(); int Total = Height+Height+Width+Width/Size; //This is where we'll contain all the tiles in std::vector<sf::Sprite> TileList(Total); //We fill the entire vector with sprites first. for (int i=0;i<Total;i++) { TileList[i].SetImage(GraphicsMan::ImageBox()[x]); } //Now we subrect all the individual tiles. for (int i=0;i<Width;i+=Size) { TileList[i].SetSubRect(sf::IntRect(i,0,i+32,i)); } //Add one to counter GraphicsMan::counter++; std::vector<int> Temp(10); return Temp; } [/cpp] GraphicsMan.h if that's of any help: [cpp] //Everything that has to do with graphics goes here class GraphicsMan { private: std::vector<sf::Image> ImageBox(); //Storage of images std::vector<sf::Sprite> SpriteBox(); //Storage for sprites that aren't used std::vector<sf::Sprite> RenderBox(); //Storage for sprites I want to render on-screen int counter; //Counts the amount of images int RendCounter; //Counts the amount of renders public: GraphicsMan(); sf::Sprite GiveRender(int i); std::vector<int> LoadTileMap(std::string imgloc,int size); void SetSprite(int id,int x,int y); //void RemSprite(int id); //void MoveSprite(int id,int x,int y); }; [/cpp]
[QUOTE=Anthos;36473799]Text[/QUOTE] You sure you fixed the linker errors? You need to add both libraries and headers to the project.
Sorry, you need to Log In to post a reply to this thread.