Jump to content
  • Advertisement
Sign in to follow this  
NIm

OpenGL newbie

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am Trying to learn to use opengl with sdl, but it has proven elusive to me. I've had considerable diffuiculty getting the example program to work with a modified version of my makefile. I almost posted here numerous times, but each time I thought of something I might try, and it worked. untill now, the problems have been in my makefile, but I think I got those worked out. I've decided to be extremely cautious in adapting this code to my project, and behold, my caution has paid off. It survived the transition from gcc to g++(no surprise), but it failed to compile when I tried modifying the code to be compatible with the rest of my project. Observe what happens when I replace stdio.h with iostream:
g++ -c -ggdb -o `sdl-config --cflags` main.cpp
g++ -ggdb -odemo `sdl-config --libs` -lGL -lGLU main.o
Where main.cpp is
/* Example of OpenGL rendering through SDL. */
#include <iostream>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <stdlib.h>

int main()
{
    /* Initialize SDL as usual. */
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
	cout<<"Error: "<<SDL_GetError()<<endl;
	return 1;
    }

    atexit(SDL_Quit);

    /* Enable OpenGL double buffering. */
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    /* Set the color depth (16-bit 565). */
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

    /* Create a 640x480, 16 bit window with support for
       OpenGL rendering. Unfortunately we won't know
       whether this is hardware accelerated. */
    if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) {
	cout<<"Error: "<<SDL_GetError()<<endl;
	return 1;
    }

    /* Set a window title. */
    SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL");

    /* We can now use any OpenGL rendering commands. */
    glViewport(80, 0, 480, 480);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
    glClearColor(0, 0, 0, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    glColor3f(1.0, 0, 0);
    glVertex3f(0.0, 1.0, -2.0);
    glColor3f(0, 1.0, 0);
    glVertex3f(-1.0, 1.0, -3.0);
    glColor3f(0, 0, 1.0);
    glVertex3f(-1.0, -1.0, -2.0);
    glEnd();
    glFlush();

    /* Display the back buffer to the screen. */
    SDL_GL_SwapBuffers();

    /* Wait a few seconds. */
    SDL_Delay(5000);

    return 0;
}


make -k all 
g++ -c -ggdb `sdl-config --cflags` main.cpp
main.cpp: In function `int main()':
main.cpp:11: error: `cout' undeclared (first use this function)
main.cpp:11: error: (Each undeclared identifier is reported only once for each 
   function it appears in.)
main.cpp:11: error: `endl' undeclared (first use this function)
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.

I have lost patience! Please, HELP ME! I try not to waste anybody's time, so don't go too far out of your way. I included iostream, and as far as I can tell I did that right. No doubt I've missed soemthing obvious.

Share this post


Link to post
Share on other sites
Advertisement
Just a thought but it might be best to avoid just adding the using namspace std directive.

If you write your own version of cout in your own namespace then you could possibly encounter conflict issues...it is best to prefix cout and endl with the std:: prefix.

Just a thought..:)

Share this post


Link to post
Share on other sites
Quote:
Original post by garyfletcher
Just a thought but it might be best to avoid just adding the using namspace std directive.
Thanks, on behalf of everyone! [smile] Thoughts are always welcome and appreciated. I am sure NIm will appreciate it.

Share this post


Link to post
Share on other sites
YEs, Thank you so much. I knew it was something obvious! Thank you for taking the time to help with something so trivial.

Share this post


Link to post
Share on other sites
Well, if you read the SDL docs they specificly say to use printf(). It might be wise of you to read the sdl docs, that along with the red book.

Share this post


Link to post
Share on other sites
Quote:
Original post by WildFire90
Well, if you read the SDL docs they specificly say to use printf(). It might be wise of you to read the sdl docs, that along with the red book.


Really... Could you provide a link to the page in the SDL docs where it specifically says this?

The only place this makes any sense for me is if you were working on the SDL library itself (it's written in C) - I don't see why it would matter in your own project.



And to the OP, one more alternative is to use
using std::cout;
using std::endl;



[Edited by - Will F on September 25, 2005 12:15:13 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!