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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - short_name

Pages: [1]
1
Graphics / Re: [SOLVED] OpenGL oddness
« on: January 26, 2022, 02:09:55 am »
Realized I shouldn't be mixing glut with sfml

2
Graphics / [SOLVED] OpenGL oddness
« on: January 26, 2022, 12:54:52 am »
The below code results in a greyscale grid of spheres rather than the ywllow spheres I expected to see. If I uncomment the lines:

 
  //sf::Text testtext;
  //testtext.setString("HELLO OPENGL");
 

Then the spheres turn yellow. but something is still off about the depth testing. The spheres on the left side of the window look correct but the ones on the right side are being rendered in the wrong order.

Anyone see what mistake(s) I am making?

#include <SFML/Graphics.hpp>
#include <math.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

int main(int argc, char **argv) {
  sf::RenderWindow window( sf::VideoMode(800,600,32), "SFML + OpenGL" );
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glEnable(GL_DEPTH_TEST);
  GLfloat lightpos[] = { 55.0, 55.0, -55.0 };
  GLfloat lightcolor[] = { 1.0, 1.0, 0.0 };
  GLfloat ambcolor[] = { 0.0, 0.0, 1.0 };
  glEnable(GL_LIGHTING);
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambcolor);
  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
  glLightfv(GL_LIGHT0,GL_AMBIENT,lightcolor);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,lightcolor);
  glLightfv(GL_LIGHT0,GL_SPECULAR,lightcolor);

  //sf::Text testtext;
  //testtext.setString("HELLO OPENGL");

  while( window.isOpen() )
  {
    sf::Event event;
    while( window.pollEvent( event ) )
    {
      if( event.type==sf::Event::Closed )
        window.close();
    }
    window.setActive();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.0, 1.0, 1.0, 70.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt( 0.0, 1.0, 5.0,
               0.0, 1.0, 4.0,
               0.0, 1.0, 0.0);

    //draw the spheres
    glColor3f(0.4f, 0.4f, 0.4f);
    int h = 10;
    for( int i = -h ; i <= h ; i++ )
    {
      for( int j = -h ; j <= h ; j++ )
      {
        glPushMatrix();
        glTranslatef(i*.4,.2,j*.4);
        glutSolidSphere(.1,30,30);
        glPopMatrix();
      }
    }

    window.display();
  }
  return 1;
}

 

3
General / Re: All rust examples fail to run
« on: May 17, 2017, 10:46:05 pm »
I forgot to run:

Code: [Select]
cargo build

4
General / [solved] All rust examples fail to run
« on: May 16, 2017, 08:08:50 pm »
I am very new to rust so I may just be doing this wrong but here is my setup:

Up to date 64 bit archlinux
rustc 1.17.0 (56124baa9 2017-04-24)
csfml 2.4-1
on commit 2e94805761c8293a4942a87cb6a3944fed0302b9 of rust-sfml
I try to run an example and I see the following:
Code: [Select]
$ cargo run --example mouse
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `/home/ed/program/rust/rust-sfml/target/debug/examples/mouse`
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  38
  Current serial number in output stream:  39

Suggestions?

5
General discussions / Re: Android and iOS ports available for testing
« on: February 03, 2014, 12:37:52 am »
No joy so far.  I can compile the android port without problems and I can run all the samples that come with the NDK on an AVD and on my phone but I cannot run the sample that comes with the android_and_IOS port.  When I try to run it on either an AVD or on my real Nexus 4 it starts and then says "Unfortunately, SFML has stopped."

Building the project seems to work fine. Here is the output from ~/android-ndk-r9/ndk-build:
Code: [Select]
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml   
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Install        : libsfml-activity.so => libs/armeabi-v7a/libsfml-activity.so
Install        : libsfml-example.so => libs/armeabi-v7a/libsfml-example.so
Install        : libsfml-system.so => libs/armeabi-v7a/libsfml-system.so
Install        : libsfml-window.so => libs/armeabi-v7a/libsfml-window.so
Install        : libsfml-graphics.so => libs/armeabi-v7a/libsfml-graphics.so
Install        : libsfml-audio.so => libs/armeabi-v7a/libsfml-audio.so
Install        : libsfml-network.so => libs/armeabi-v7a/libsfml-network.so
Install        : libstlport_shared.so => libs/armeabi-v7a/libstlport_shared.so
Install        : libopenal.so => libs/armeabi-v7a/libopenal.so
Install        : libsndfile.so => libs/armeabi-v7a/libsndfile.so
Here are what I think are the relevant log messages when it crashes:
Code: [Select]
02-02 16:30:52.743: I/ActivityManager(601): Start proc com.example.sfml for activity com.example.sfml/android.app.NativeActivity: pid=22731 uid=10155 gids={50155}
02-02 16:30:52.763: I/SearchController(24544): #onHotwordDetectorStopped
02-02 16:30:52.763: I/MicrophoneInputStream(24544): mic_close
02-02 16:30:52.773: D/dalvikvm(826): GC_CONCURRENT freed 495K, 6% free 9518K/10080K, paused 2ms+1ms, total 15ms
02-02 16:30:52.843: D/dalvikvm(24544): threadid=49: thread exiting, not yet detached (count=0)
02-02 16:30:52.843: D/dalvikvm(24544): threadid=37: thread exiting, not yet detached (count=0)
02-02 16:30:52.893: I/Adreno-EGL(22731): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
02-02 16:30:52.914: D/dalvikvm(826): GC_CONCURRENT freed 388K, 6% free 9515K/10080K, paused 1ms+1ms, total 14ms
02-02 16:30:53.084: D/dalvikvm(826): GC_CONCURRENT freed 483K, 6% free 9520K/10080K, paused 2ms+2ms, total 21ms
02-02 16:30:53.444: A/libc(22731): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 22748 (om.example.sfml)
02-02 16:30:53.504: I/DEBUG(171): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-02 16:30:53.504: I/DEBUG(171): Build fingerprint: 'google/occam/mako:4.4.2/KOT49H/937116:user/release-keys'
02-02 16:30:53.504: I/DEBUG(171): Revision: '10'
02-02 16:30:53.504: I/DEBUG(171): pid: 22731, tid: 22748, name: om.example.sfml  >>> com.example.sfml <<<
02-02 16:30:53.504: I/DEBUG(171): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
and the backtrace:
Code: [Select]
02-02 16:30:53.654: I/DEBUG(171): backtrace:
02-02 16:30:53.664: I/DEBUG(171):     #00  pc 00000000  <unknown>
02-02 16:30:53.664: I/DEBUG(171):     #01  pc 000417a3  /system/lib/egl/libGLESv2_adreno.so (glGetString+16)
02-02 16:30:53.664: I/DEBUG(171):     #02  pc 0001c909  /system/lib/egl/libGLESv1_CM_adreno.so (Load_Gll_2_0+984)
02-02 16:30:53.664: I/DEBUG(171):     #03  pc 00021d03  /system/lib/egl/libGLESv1_CM_adreno.so (gliMakeCurrent+18)
02-02 16:30:53.664: I/DEBUG(171):     #04  pc 00024d89  /system/lib/egl/libGLESv1_CM_adreno.so (oglSetBuffers+48)
02-02 16:30:53.664: I/DEBUG(171):     #05  pc 0001c7f4  /system/lib/egl/libEGL_adreno.so (eglGLUpdateSurfaces+648)
02-02 16:30:53.664: I/DEBUG(171):     #06  pc 00010b50  /system/lib/egl/libEGL_adreno.so (qeglDrvAPI_eglMakeCurrent+628)
02-02 16:30:53.664: I/DEBUG(171):     #07  pc 00006b0c  /system/lib/egl/libEGL_adreno.so (eglMakeCurrent+16)
02-02 16:30:53.664: I/DEBUG(171):     #08  pc 0000d3e5  /system/lib/libEGL.so (android::egl_display_t::makeCurrent(android::egl_context_t*, android::egl_context_t*, void*, void*, void*, void*, void*, void*)+84)
I have tried it using API Level 17, 18 and 19 on AVD's. 
I am using ndk-r9 per the post by sonkun at November 29, 2013, 05:18:00 PM
I believe I configured cmake properly, but I attached a screenshot of my cmake-gui configuration.

6
Thank you again Laurent, I read the tutorials 'Drawing 2d stuff' and 'Using OpenGL in a SFML window' but did not realize that the RenderTexture had to be set active in the same way that it describes for windows.

7
I am using a modified version of the opengl.cpp example file.  I am now able (due to some previous help from Laurent) to bind an sfml texture directly to an OpenGL object.  I am trying to bind a very simple RenderTexture to a OpenGL cube using getTexture().  Eventually I intend to draw sprites to the texture but for now all I am doing is clearing it with red.  The result is that the cube is invisible.  Can someone please tell me what I am doing wrong?

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    sf::RenderTexture texture;
    texture.create(500, 500);
    texture.clear(sf::Color::Red);
    sf::Texture::bind( & texture.getTexture() );

    // Enable Z-buffer read and write
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Create a clock for measuring the time elapsed
    sf::Clock clock;

    // Start game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();

            // Escape key : exit
            if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                window.close();

            // Adjust the viewport when the window is resized
            if (event.type == sf::Event::Resized)
                glViewport(0, 0, event.size.width, event.size.height);
        }

        // Activate the window before using OpenGL commands.
        // This is useless here because we have only one window which is
        // always the active one, but don't forget it if you use multiple windows
        window.setActive();

        // Clear the depth buffer
        glClear(GL_DEPTH_BUFFER_BIT);
        window.clear(sf::Color::Black);
        texture.clear(sf::Color::Red);

        //sf::Texture * t1;
        //t1.loadFromFile( "./resources/1.png" );
        //t1 = texture.getTexture();
        sf::Texture::bind( & texture.getTexture() );

        float x = 0;
        float y = 0;

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(x, y, -100.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);

        // Draw a cube
        float size = 20.f;
        glBegin(GL_QUADS);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(-size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(-size, -size,  size);

            glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, -size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, size,  size);

        glEnd();

        // Finally, display the rendered frame on screen
        window.display();
    }

    return EXIT_SUCCESS;
}
 

8
Graphics / Re: Binding sfml texture to OpenGL object in SFML 2
« on: June 25, 2013, 12:59:34 am »
That was it, thanks!

9
Graphics / Re: Binding sfml texture to OpenGL object in SFML 2
« on: June 24, 2013, 08:42:11 pm »
Yes load from file is successful.  I tested this by changing to a non existent filename and I get a run-time error that the filename doesn't exist. As the code is written now I get no runtime errors.

10
Graphics / [SOLVED] Binding sfml texture to OpenGL object in SFML 2
« on: June 24, 2013, 02:11:12 am »
I tried to edit the opengl.cpp example file to bind an sfml texture to the spinning cube rather than using a GLUint.  The file even says "We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function)" but I have not been able to do so.  The result is a spinning white cube.  Can someone tell me what I am missing please?

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    // Load an OpenGL texture.
    // We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
    // but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
    //GLuint texture = 0;
    //{
    //    sf::Image image;
    //    if (!image.loadFromFile("resources/texture.jpg"))
    //        return EXIT_FAILURE;
    //    glGenTextures(1, &texture);
    //    glBindTexture(GL_TEXTURE_2D, texture);
    //    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
    //    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    //}

    sf::Texture t1;
    t1.loadFromFile( "./resources/1.png" );
    sf::Texture::bind( &t1 );

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Create a clock for measuring the time elapsed
    sf::Clock clock;

    // Start game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();

            // Escape key : exit
            if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                window.close();

            // Adjust the viewport when the window is resized
            if (event.type == sf::Event::Resized)
                glViewport(0, 0, event.size.width, event.size.height);
        }

        // Activate the window before using OpenGL commands.
        // This is useless here because we have only one window which is
        // always the active one, but don't forget it if you use multiple windows
        window.setActive();

        // Clear the depth buffer
        glClear(GL_DEPTH_BUFFER_BIT);
        window.clear(sf::Color::Black);

        float x = 0;
        float y = 0;

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(x, y, -100.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);

        // Draw a cube
        float size = 20.f;
        glBegin(GL_QUADS);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(-size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(-size, -size,  size);

            glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, -size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, size,  size);

        glEnd();

        // Finally, display the rendered frame on screen
        window.display();
    }

    return EXIT_SUCCESS;
}
 

11
Graphics / small adjustment resolved it
« on: January 29, 2012, 10:37:23 pm »
I changed sf::Window to sf::RenderWindow and kablamo it works now.

12
Graphics / [Solved]textured cube
« on: January 29, 2012, 05:43:31 am »
I am trying to create a cube based on the "Using OpenGL" tutorial. I am using sfml 2.0. The problem is the cube shows up as plain white no matter if I bind the texture or not. I am not an expert on OpenGL so I am geussing that I am making a silly mistake. I found another post at http://www.sfml-dev.org/forum/viewtopic.php?t=2041&sid=1397d9c455d32225fdcdc4bed5542c29 that says I need to set the texture coordinates for each quad which I think I am doing correctly. Any suggestions would be greatly appreciated!

Code: [Select]

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>

using namespace std;
int main()
{
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
    sf::Clock Clock;
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);
    sf::Texture Texture;
    if( Texture.LoadFromFile( "test.png" ) )
    {
      cout << "image loaded!" << endl;
    }
    else
    {
      cout << "image not found!" << endl;
    }
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);
    double seconds = 0;
    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
                App.Close();
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);
        seconds = Clock.GetElapsedTime() / 1000.0;
        glRotatef( seconds * 50 , 1.f, 0.f, 0.f);
        glRotatef( seconds * 30 , 0.f, 1.f, 0.f);
        glRotatef( seconds * 90 , 0.f, 0.f, 1.f);
        //Uncommenting the next line does not affect the cube at all
        //Texture.Bind();

        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
        glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, -50.f);
        glTexCoord2f(1, 1); glVertex3f( 50.f,  50.f, -50.f);
        glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);

        glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, 50.f);
        glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, 50.f);
        glTexCoord2f(1, 1); glVertex3f( 50.f,  50.f, 50.f);
        glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, 50.f);

        glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
        glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, -50.f);
        glTexCoord2f(1, 1); glVertex3f(-50.f,  50.f,  50.f);
        glTexCoord2f(1, 0); glVertex3f(-50.f, -50.f,  50.f);

        glTexCoord2f(0, 0); glVertex3f(50.f, -50.f, -50.f);
        glTexCoord2f(0, 1); glVertex3f(50.f,  50.f, -50.f);
        glTexCoord2f(1, 1); glVertex3f(50.f,  50.f,  50.f);
        glTexCoord2f(1, 0); glVertex3f(50.f, -50.f,  50.f);

        glTexCoord2f(0, 1); glVertex3f(-50.f, -50.f,  50.f);
        glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
        glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);
        glTexCoord2f(1, 1); glVertex3f( 50.f, -50.f,  50.f);

        glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f,  50.f);
        glTexCoord2f(0, 0); glVertex3f(-50.f, 50.f, -50.f);
        glTexCoord2f(1, 0); glVertex3f( 50.f, 50.f, -50.f);
        glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f,  50.f);
        glEnd();

        App.Display();
    }
    return EXIT_SUCCESS;
}

13
General / danke schön
« on: December 22, 2011, 09:08:31 am »
Thanks Laurent! I have never written an assignment operator before but I figured it out with a little help from scroogle  :D .

Here is the new compilable version of code for anyone who is interested:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>

using namespace std;
class GameObject {
  public:
    GameObject( sf::RenderWindow &render_window ) : render_window( render_window )
    {
    };
    GameObject( const GameObject& game_object ) : render_window( game_object.render_window )
    {
    };
    GameObject& operator= (const GameObject & game_object )
    {
    };

  private:
    sf::RenderWindow& render_window;
};

int main()
{
  vector<GameObject> test;
  sf::RenderWindow app;
  GameObject go (app);
  test.push_back(go);
}
[\code]

14
General / [SOLVED]vector of class owning a render window
« on: December 22, 2011, 07:01:14 am »
I am trying to create a vector of a class which owns a render window and I think I am running into a problem because the render window is non copyable. I am able to pass a reference of the render window to the constructor but when I try to push the object I create onto the vector I run into trouble.

My code looks like this:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>

using namespace std;
class GameObject {
  public:
    GameObject::GameObject( sf::RenderWindow &render_window ) : render_window( render_window )
    {
    };

  private:
    sf::RenderWindow& render_window;
};

int main()
{
  vector<GameObject> test;
  sf::RenderWindow app;
  GameObject go (app);
  test.push_back(go);
}

but when I try to compile I get the output:
Code: [Select]

g++ -o game example.cpp -lsfml-graphics -lsfml-window -lsfml-system
example.cpp:8:5: error: extra qualification âGameObject::â on member âGameObjectâ [-fpermissive]
example.cpp: In member function âGameObject& GameObject::operator=(const GameObject&)â:
example.cpp:6:7:   instantiated from âvoid std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<GameObject*, std::vector<GameObject> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = GameObject*]â
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:834:4:   instantiated from âvoid std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::value_type = GameObject]â
example.cpp:22:20:   instantiated from here
example.cpp:6:7: error: non-static reference member âsf::RenderWindow& GameObject::render_windowâ, canât use default assignment operator
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/vector:70:0,
                 from /usr/include/SFML/Window/VideoMode.hpp:32,
                 from /usr/include/SFML/Window.hpp:39,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from example.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/vector.tcc: In member function âvoid std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<GameObject*, std::vector<GameObject> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = GameObject*]â:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/vector.tcc:317:4: note: synthesized method âGameObject& GameObject::operator=(const GameObject&)â first required here


I tried adding a copy constructor:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>

using namespace std;
class GameObject {
  public:
    GameObject::GameObject( sf::RenderWindow &render_window ) : render_window( render_window )
    {
    };
    GameObject( const GameObject& game_object ) : render_window( game_object.render_window )
    {
    };

  private:
    sf::RenderWindow& render_window;
};

int main()
{
  vector<GameObject> test;
  sf::RenderWindow app;
  GameObject go (app);
  test.push_back(go);
}


but then I get the very similar output:
Code: [Select]

g++ -o game example2.cpp -lsfml-graphics -lsfml-window -lsfml-system
example2.cpp:7:5: error: extra qualification âGameObject::â on member âGameObjectâ [-fpermissive]
example2.cpp: In member function âGameObject& GameObject::operator=(const GameObject&)â:
example2.cpp:5:7:   instantiated from âvoid std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<GameObject*, std::vector<GameObject> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = GameObject*]â
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:834:4:   instantiated from âvoid std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::value_type = GameObject]â
example2.cpp:23:20:   instantiated from here
example2.cpp:5:7: error: non-static reference member âsf::RenderWindow& GameObject::render_windowâ, canât use default assignment operator
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/vector:70:0,
                 from /usr/include/SFML/Window/VideoMode.hpp:32,
                 from /usr/include/SFML/Window.hpp:39,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from example2.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/vector.tcc: In member function âvoid std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = GameObject, _Alloc = std::allocator<GameObject>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<GameObject*, std::vector<GameObject> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = GameObject*]â:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/vector.tcc:317:4: note: synthesized method âGameObject& GameObject::operator=(const GameObject&)â first required here


I am sure I am missing something obvious as I am new to this but any responses will be greatly appreciated!

Pages: [1]
anything