Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by iwoplaza

  1. There probably are, but writing your own .obj file loader is a good challenge :). I wrote my own some time ago, and I even have my own model format now xD.   I used stdio's FILE to load the file line by line, and then check if the line starts with "v" (for the verticies), and if yes, it used fscanf to get the rest of the data in the line :).
  2. The Y axis is the up direction of my scene. 
  3. Hello everybody.   As I said in the topic, I have a problem with my shader for point lights. I followed a ton of tutorials about phong lighting and per fragment point lighting. Still, after all these tutorials, I still have this problem:   The light only lits up objects in the positive X direction.   Here is my shader code: VERTEX SHADER #version 120 varying vec2 texCoord; varying vec3 position; varying vec3 normal; varying vec3 tangentSurf2light; varying vec3 tangentSurf2view; uniform vec3 lightPos; void main() { gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; position = vec3(gl_ModelViewMatrix * gl_Vertex); normal = normalize(gl_NormalMatrix * gl_Normal); texCoord=gl_MultiTexCoord0.xy; vec3 tangent; vec3 v1=cross(gl_Normal,vec3(0.0,0.0,-1.0)); vec3 v2=cross(gl_Normal,vec3(0.0,-1.0,0.0)); if(length(v1)>length(v2)){ tangent=v1; }else{ tangent=v2; } vec3 t = normalize(gl_NormalMatrix * tangent); vec3 b = cross(normal,t); mat3 mat = mat3(t.x,b.x,normal.x, t.y,b.y,normal.y, t.z,b.z,normal.z); vec4 var = vec4(lightPos,1.0); vec3 lightLoc = vec3(gl_ModelViewMatrix * var); vec3 vector = normalize(lightLoc-position); tangentSurf2light=mat*vector; vector=normalize(-position); tangentSurf2view=mat*vector; } FRAGMENT SHADER #version 120 uniform sampler2D texture; uniform sampler2D normalmap; uniform sampler2D specularmap; uniform vec3 lightPos; varying vec2 texCoord; varying vec3 position; varying vec3 normal; uniform vec3 matDiffuse; uniform vec3 matSpecular; uniform vec3 lightAmbient; uniform vec3 lightDiffuse; uniform vec3 lightSpecular; varying vec3 tangentSurf2light; varying vec3 tangentSurf2view; void main(){ vec4 var = vec4(lightPos,1.0); vec3 lightLoc = vec3(gl_ModelViewMatrix * var); float dist=length(position-lightLoc); float att=1.0/(1.0+0.1*dist+0.01*dist*dist); vec3 ambient = vec3(texture2D(texture,texCoord)) * lightAmbient; vec3 surf2light = normalize(tangentSurf2light); vec3 norm = normalize(texture2D(normalmap,texCoord).xyz*2.0-1.0); float dcont = max(0.0, dot(norm,surf2light)); vec3 diffuse = dcont * vec3(texture2D(texture,texCoord)) * lightDiffuse; vec3 surf2view = normalize(tangentSurf2view); vec3 reflection = reflect(-surf2light,norm); float scont = pow(max(0.0,dot(surf2view,reflection)),texture2D(specularmap,texCoord).x*50); vec3 specular = scont*lightSpecular*matSpecular*att; gl_FragColor = vec4(ambient+diffuse+specular,1.0); } Thanks in advance!
  4. You have to devide it by two, because you are actually trying to get the average of these two textures. Imagine that you have a red texture and a black texture. By mixing these two you would expect it to turn out as a darker red. It wouldn't, because you are not getting the average of them, you are just adding them together, so: (red: 1.0, green: 0.0, blue: 0.0) + (red: 0.0, green: 0.0, blue: 0.0) ==(red: 1.0, green: 0.0, blue: 0.0) BUT (red: 1.0, green: 0.0, blue: 0.0)/2 + (red: 0.0, green: 0.0, blue: 0.0)/2 ==(red: 0.5, green: 0.0, blue: 0.0)   I hope it helped :).
  5. Hello everybody!   Okay, let's say that my application screen looks like that:       And I want it to look like this:     The scenery at the first picture contains of two planes on top of each other that have different textures.   What I want is the thing that happened at the second picture. It want it to cut the part of the plane wherever I want based of this texture:   I am using SDL for handling events, and OpenGL for drawing.   Thanks in advance .  
  6. Thank you very much :D! +1 for you. But what if I had a vector of 2D points, and I would want all of them to make holes in "the texture", and the number of the points is specified in a variable, so it can change anytime? Can I add multiple textures of "the hole" to the multitexture? Or is it possible to combine all of the "holes" that point made into one texture, and use it in the multi-texture?   Thanks in advance :)
  7. Hello there.   I want to make a list of entities that are gonna be updated every tick. So, I created a class named Entity, and gave it a couple of functions: class Entity{ public: int uniqueID; Vec3f loc; Vec2f res; Vec2f vel; float rot; virtual void onUpdate(); virtual void onSpawned(); virtual string getNameID(); vector<GameData> gameData; }; Then, I created a vector of these entities: vector<Entity> entities; After that, I wanted an arrow entity, so I created a new class EntityArrow that is an extension of Entity: class EntityArrow : public Entity{ public: EntityArrow(); EntityArrow(Vec3f argLoc,Vec2f argRes); string getNameID(); void onUpdate(); void onSpawned(); }; And now comes the problem, when I try to add a new EnttiyArrow to the entities list: entities.push_back(EntityArrow()); it is still treated as an Entity. For instance, if I overrided the onUpdate() function in EntityArrow to print out something in the console, it would do something that is in the Entity's onUpdate() , and not the EntityArrow's. I have already tried to make a vector out of references to Entity class : vector<Entity*> entities , but I still have a lot of problems with it.   Is there a better way to do it? Thanks in advance :).
  8. So I should use this method right? vector<Entity*> entities   Well, if yes, than I still have problems with it. Sure, it works for the aspect of overriding the functions properly, but sometimes when I try to render it or just add another entity, it doesn't show up, or just doesn't add to the vector.   Is this method of adding the Entity into the vector correct? EntityArrow arrow = EntityArrow(); entities.push_back(&arrow);
  9. iwoplaza

    In need of an algorythm!

    Hi. The picture shows a point and a line in a 2d space. Does someone know what algorythm do I use to calculate the '?' in the picture? It is the distance between the 'point' and the line, but the angle between the line and the "distance line" has to be 90 degrees. I want to use that in my physics engine. And can someone help me find the 3D equivalent of that as well?   Thanks in advance!  
  10. iwoplaza

    In need of an algorythm!

    Thanks a lot man, that got me on the track :).
  11. Hello everyone. My problem is that on my computer, eveything works fine, I mean, all of the textures are working, fps is great and all. Here comes the problem... on other computers, it doesn't, some of the textures aren't working, and FPS is horrible. The texture thing is probably a power of two thingy, cuz every power of two resolution texture is working, but others are not. What is wrong with the FPS's?   Drawing: OpenGL Texture Loading: DevIL Language: C++   Thanks in advance!
  12. Than let's begin. First I will show you how my GUI works and looks.Then you can choose what you want to learn. Here is my GUI: And about library that is made for GUI. Like you, I've been searching the simple way to do it, but I couldn't find it. So I begun to make my own code to render these GUI things. Tell me what things you'd like to learn.
  13. I maked rendered text and own GUI for myself . I can tell you how to do that.If you are interested , tell me and I will help you.
  14. I have a question. How can I get vertex positions from camera view in OpenGL. Example: Wherever the camera is, I want to get vertex positions from camera view. I'm using OpenGL for drawing. I'm from Poland so if you could use some clear language. Thanks in advance.
  15. I have a problem. I wrote a modeler to create models with my format, but I want to be able to select individual vertices with my mouse or select which model I want to edit. Screen of the program: So can you give me some tutorials or tips. I'm using: OpenGL - drawing. DevIL - images. fStream - FileLoader. I'm from Poland so if you could use some clear language. Thanks in advance.
  16. Thanks man. I was thinking of it before but i was wondering if there is better way to do it. But thanks . If anyone knows another way of doing it please tell me.
  17. I have a problem with the library "fstream", because I'd like to read 100 characters by using the FOR loop. For example, a text file from I want to read the characters look like this: A B C D And I want to read the characters one by one to four variables CHAR using a loop. But I do not know how to do it . Can you help? Thanks in advance.
  18. I would like to create buttons. And when you click them, do some functions. But i have problem with button actions . Some of my code: //---- Header File---- class Button{ public: //variables initiating like float x,y,z... void func(void); void draw(){ //Some drawing } void CheckButtonClick(float mx, float my,int key,int state){ if(mx >= x && mx <= x+w && my >= y && my <= y+h && state == 0 && key == 0){ click = true; func(); }else click = false; } }; //----Main File---- void AddButton(Button &button,string text,void func(),float x,float y,float z,float w,float h,float s,float r,float g,float b,GLuint tex,GLuint clicktex){ button.tex = tex; button.clicktex = clicktex; button.func() = func(); button.textsize = s; button.text = text; button.x = x; button.y = y; button.z = z; button.w = w; button.h = h; button.color[0] = r; button.color[1] = g; button.color[2] = b; } Button button_file, void close(){ exit(0); } void InitRendering(){ _buttondark = loadTexture ("Data/IvoGui/buttondark.tga"); _buttondark_click = loadTexture ("Data/IvoGui/buttondark_click.tga"); AddButton(button_help,"Pomoc",close(),133,5,0.001f,64,16,0.9f,1.0f,1.0f,1.0f,_buttondark,_buttondark_click); } It gives me an error: invalid use of void expression Without button actions everything works fine. Can you help me with this actions? Thanks in advance.
  19. iwoplaza

    Problem with functions!

    Thanks to everyone, but i figured it out for myself .
  20. iwoplaza

    Problem with functions!

    Please proceed, and write modified piece of code.
  21. iwoplaza

    Problem with functions!

    What you mean by concrete implementation of Button::func.
  22. iwoplaza

    Problem with functions!

    Button button_file, I think you mistyped a semicolon here, but I'm pretty sure it's a copy/paste mistake. This is followed by a "void", which explains the error message (C++ compiler errors generally make no sense if you made a typo, so you have to look through to try and find it), but I doubt this is the source of the error, could you post the revised code if this is so? [/quote] "Button button_file," was a copy/paste mistake . But if you want i can give you code that is needed (some of header file, some of main that is about button), or a full code for a further investigation.
  23. iwoplaza

    FStream Problem

    Thanks to all, but I solved it for myself . I changed the contents of a text file from: a b c d ... (one hundred characters) to: abcdefghijk ... (one hundred characters) Instead of loading the characters one by one, I loaded a line of characters to an array of char. . Example: char characters[100]; char loadline[100]; fstream input; input.open("fontprops.txt"); input >> loadline; for(int i = 0;i < 100;i++) { characters.number = i; characters.character = loadtext; }
  24. I'm making three-dimensional application in OpenGL, which generates a random blocks in the world (something like Minecraft). This is my script to generate blocks: void GenBlocks(){ int currblock; int currXline; int currZline; int randID; for(currblock = 0,currXline = 1,currZline = 1;currblock < blockAM;currblock++,currXline++){ randID = rand() % 2 + 1; if(currXline > pierw(blockAM)){ currXline = 1; currZline++; } block[currblock].x = currXline*3; block[currblock].y = 0; block[currblock].z = currZline*3; block[currblock].id = randID; } } But every time when I run the application, it generates the same! Thanks in advance.
  • 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!