SFML community forums
General => General discussions => Topic started by: molmasepic on February 09, 2011, 12:06:41 am
-
hey i heard that i can use normal opengl tutorials with SFML, but the thing is:
im not sure on which tutorials are good...
im wondering if maybe someone knows a good tutorial site for opengl(with sfml would be even better) just so i dont get super confused ._.
thanks in advance! :D
EDIT: my IDE is Code Blocks and my Compiler is MinGW if that helps
-
There is sample named "OpenGL" you can start here :p
And : http://www.sfml-dev.org/tutorials/1.6/window-opengl-fr.php
May be this site can help you
http://nehe.gamedev.net/
Good luck ;)
-
I support Oneiros' proposal. (Except I wouldn't link to the French tutorial :P )
Read carefully «SFML and Code::Blocks (MinGW)» from «Getting started» then jump to «Window package» section and focus on SFML code (possibly skip OpenGL stuff from now).
Then I recommend you to read lesson 2 from nehe (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02) (and the next ones) skip the Windows related code and try to adapt the code for handling events to use SFML (like the «Finally change the code to toggle window / fullscreen mode..» part from lesson 2). (Well, focus on the OpenGL functions.)
An also interesting book is this one : the red book (http://fly.cc.fer.hr/~unreal/theredbook/). It's maybe a better choice than nehe tutorial because it focus on OGL stuff.
But you might be interested by using SFML Graphics module. :wink:
-
ok ive tried the sample but i got a small error..
|undefined reference to `gluPerspective@32'|
any ideas? did i miss something?
@ Hiura, by "windows related" you mean like the OS? thats what im using
-
Oups sorry for french link (i'm french ^^)
I think you've not link openGl lib
-
You forget to link against opengl lib. ;-)
see http://www.sfml-dev.org/forum/viewtopic.php?p=26330#26330
-
Oups sorry for french link (i'm french ^^)
I think you've not link openGl lib
okay i got it to work(it was glu32)
-
@ Hiura, by "windows related" you mean like the OS? thats what im using
Yes. Because if you use SFML to handle the window you won't have to use any Windows specific code.
-
@ Hiura, by "windows related" you mean like the OS? thats what im using
Yes. Because if you use SFML to handle the window you won't have to use any Windows specific code.
ah so window(the app)
i thought the operating system(windows) xD
ok i better get started, thanks
-
I think there is still a little bit of misunderstanding, Sorry ^^'
-by window or windows (lower case) I'm speaking of user interface
-by Windows (capital w) I'm referring to the OS.
But it's pretty much the same as the window related code is for Windows in the nehe tutorials... Ok I shut up! :lol:
-
ohhhh ok i get you
-
hey ive been working (or trying to work) with OpenGL for some time now. and i have a couple new questions.
a tutorial i found is videotutorialsrock.com because i like video tutorials xD
but i noticed when i put the opengl stuff into my current sfml project, it never renders right...
trying to say that when i clear window(glClear) only one or two sfml sprites show up.
does this mean that im going to have to start over with opengl fully? or maybe im doing this wrong..?
if anyone needs more info please let me know, i will pull up some code also if that is needed.
thanks again for the tutorials
-
Can you post the relevant part of your code here ?
-
//sfml stuff(main function)
glClearDepth(1.f);
glClearColor(0.f,0.f,0.f,0.f);
/////z buffer
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
/////perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(-20.f,1.f,1.f,200.f);
//sfml loading/first placement
//sfml main loop
//input
GameWind.SetActive();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glVertex3f(3.f,3.f,3.f);
glVertex3f(3.f,6.f,3.f);
glVertex3f(6.f,6.f,3.f);
glVertex3f(6.f,3.f,3.f);
glColor3f(0.5f,0.8f,0.f);
glEnd();
//some subrect updating and then the drawing
the only thing that actually drew was the stuff that i set positions for BEFORE i cleared the gl window
if this is too vague then ill update xD
[/code]
-
I might have an idea but I'd like the full main to be sure.
-
gave you a PM, reply here xD
-
a useful link for the next time : http://pastebin.com/ :wink:
Ok, so that was I was thinking of. You should read § Mixing with OpenGL from Tutorial - Graphics - Using render windows (http://www.sfml-dev.org/tutorials/1.6/graphics-window.php) :wink:
-
alright cool, that fixes that question. now heres another one.
when i was drawing the figure onscreen, i would only see a small portion of it on the screen, other than that it will not show...
im thinking its the gluPerspective() thats probably too close or far, but im not sure.
also if you see that i have a set coo in there, i dont see it in color either..
any ideas?
-
Sorry, I've no idea about this right now. maybe someone else can help you.
-
yay i found the problem, i forgot to setup a gltranslate()
thanks for the help Hiura i appreciate it :D
-
hey im at a point where im using textures.
is there a way to use a SFML image/sprite for the texture?
if not then what is a way to laod a PNG? (i like PNGs xD)
the tut i found is only BMP
-
There is an OpenGL example in the SDK. And PNG works just the way BMP does :)
-
ok what you said is very vague to me(might just be me ._.)
and when you say that PNGs work the same, in the tutorial im using, it doesnt let me load other than BMP
also is there seriously no way to use a SFML sprite/image instead?
just something to fill this in:
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,image->width(THIS),image->height(THIS),0,GL_RGB,GL_UNSIGNED_BYTE,image->pixels(AND THIS));
-
I don't see the problem. You load a PNG file using sf::Image::LoadFromFile(), then you access the image's texture as explained in the OpenGL tutorial.
If something doesn't work, you have to tell us what exactly. But try to follow the SFML tutorials.
-
hey ive been wondering something..
is it possible to load a sprite as a texture(i got it to work as an image before)
what im trying to do is use a subrect of that image(say its 30x15 and i wanna use ponly 15x15 of it)
heres what i got so far:
GLuint LoadTexture(sf::Sprite image)
{
GLuint Texture;
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 17, 22, GL_RGBA, GL_UNSIGNED_BYTE,image.GetImage().GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
return Texture;
}
and in main...
GLuint _texture[2];
sf::Image itexture[2];
sf::Sprite stexture[2];
itexture[0].LoadFromFile("Awesome.png");
itexture[1].LoadFromFile("Graphics/Player Sprite.png");
stexture[1].SetImage(itexture[1]);
stexture[1].SetSubRect(sf::IntRect(0,0,17,22));
//_texture[0] = LoadTexture(itexture[0]);
_texture[1] = LoadTexture(stexture[1]);
hopefully the code can give you some vision of what will happen
-
scratch that other question if it doesnt make sense ._.
how bout a way to use only PART of an image that is loaded for a texture?(width 50 height 50) and using only(25x25) of the image
is THIS possible?
-
stexture[1].SetSubRect(sf::IntRect(0,0,17,22));
This line of code only affects the sf::Sprite and doesn't change the sf::Image object. That's why you don't get what you expected.
You can improve your function by changing its parameter to a const sf::Image & (no memory copy with references).
Now,
how bout a way to use only PART of an image that is loaded for a texture?
You can do almost everything with raw pixel data (GetPixelsPtr() method). Understand how the array is structured and apply the correct algorithm to get what you want.
But here you can simply use sf::Image::Copy method (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Image.htm#408c40c8675363adfa96a8b9a9576bc2). :wink:
-
You don't need to split your images, just keep everything grouped and use texture coordinates to display sub-rects.
-
Hiura, im having a hard time figuring what you said out...
this is what i got so far..
GLuint _texture[2];
sf::Image ictexture[2];
sf::Image itexture[2];
itexture[0].LoadFromFile("Block.png");
itexture[1].LoadFromFile("Cursor.png");
ictexture[1].Copy(itexture[1],10,10,sf::IntRect(0,0,10,10),true);
ictexture[1].SaveToFile("Graphics/Texture/texture1.png");
_texture[0] = LoadTexture(itexture[0]);
_texture[1] = LoadTexture(ictexture[1]);
when doing this i get Console errors saying:
Failed to write PNG image. Reason: image width or height is zero in IHDR
Trying to access the pixels of an empty image<<<i think this is from opengl..
nevermind that, forgot image.create()