Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenGL and SFML  (Read 13919 times)

0 Members and 1 Guest are viewing this topic.

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #15 on: February 13, 2011, 09:31:47 pm »
gave you a PM, reply here xD

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
OpenGL and SFML
« Reply #16 on: February 13, 2011, 09:41:30 pm »
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  :wink:
SFML / OS X developer

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #17 on: February 13, 2011, 09:58:44 pm »
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?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
OpenGL and SFML
« Reply #18 on: February 13, 2011, 10:56:39 pm »
Sorry, I've no idea about this right now. maybe someone else can help you.
SFML / OS X developer

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #19 on: February 13, 2011, 11:02:41 pm »
yay i found the problem, i forgot to setup a gltranslate()

thanks for the help Hiura i appreciate it :D

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #20 on: February 14, 2011, 03:48:51 am »
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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
OpenGL and SFML
« Reply #21 on: February 14, 2011, 04:05:20 am »
There is an OpenGL example in the SDK. And PNG works just the way BMP does :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #22 on: February 14, 2011, 04:26:53 am »
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:

Code: [Select]
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,image->width(THIS),image->height(THIS),0,GL_RGB,GL_UNSIGNED_BYTE,image->pixels(AND THIS));

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
OpenGL and SFML
« Reply #23 on: February 14, 2011, 02:22:40 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #24 on: February 15, 2011, 04:34:53 am »
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:

Code: [Select]
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...

Code: [Select]
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

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #25 on: February 15, 2011, 05:15:40 am »
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?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
OpenGL and SFML
« Reply #26 on: February 15, 2011, 10:37:08 am »
Code: [Select]
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,
Quote
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.   :wink:
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL and SFML
« Reply #27 on: February 15, 2011, 10:43:12 am »
You don't need to split your images, just keep everything grouped and use texture coordinates to display sub-rects.
Laurent Gomila - SFML developer

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
OpenGL and SFML
« Reply #28 on: February 15, 2011, 06:53:56 pm »
Hiura, im having a hard time figuring what you said out...


this is what i got so far..

Code: [Select]
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()

 

anything