Archived

This topic is now archived and is closed to further replies.

SDL/OpenGL - What's wrong with this code? (Windows)

This topic is 5624 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''ve got this simple code for OpenGL/SDL to run together but it''s not compiling. I''m assuming that this is because under windows I would have to do something different, and I took this code from a Linux book:
      
#include <SDL.h>
#include <GL/GL.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argv, char argv[]){
	int i;

	if(SDL_Init(SDL_INIT_VIDEO) != 0){
		printf("Error.");
		return 1;
	}

	atexit(SDL_Quit);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	SDL_GL_Attribute(SDL_GL_RED_SIZE, 5);
	SDL_GL_Attribute(SDL_GL_GREEN_SIZE, 6);
	SDL_GL_Attribute(SDL_GL_BLUE_SIZE, 5);

	if(SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL){
		printf("Error.");
		return 1;
	}

	SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL");

	 /* Our shading model--Gouraud (smooth). */
    glShadeModel( GL_SMOOTH );

    /* Culling. */
    glCullFace( GL_BACK );
    glFrontFace( GL_CCW );
    glEnable( GL_CULL_FACE );


	glViewport(80, 0, 480, 480);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustrum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
	glClear Color(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, -2.0);
	glColor3f(0, 0, 1.0);
	glVertex3f(-1.0, -1.0, -2.0);
	glEnd();
	glFlush();

	SDL_GL_SwapBuffers();

	SDL_Delay(5000);

	return 0;
}
      
End the errors: d:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing '';'' before type ''void'' d:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ''WINGDIAPI'' : missing storage-class or type specifiers d:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found Hopefully it''s just something stupid I didn''t notice and someone will nicely tell me that I don''t have to deal with the WinAPI when I''m using SDL/OpenGL thanks in advance. (Yes.. I linked all the .lib files) ------------------------------ Have a r0xx0r 1337 day plx!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the problems are in gl.h, so maybe you need to include something before them. i would try windows.h because it says something about WINGDAPI.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
or maybe the include order is bad. just guessing and something that you might try.

Share this post


Link to post
Share on other sites
Is there anything else I need to do with SDL/OpenGL to ensure that my OpenGL apps will run correctly? Texturing doesn''t seem to be working for me, and I''m pretty sure that the problem isn''t the code.

Are there more calls I need to make to SDL_GL_SetAttribute() to make certain things work?

Are there any documents or examples of SDL being used with OpenGL on the web that anyone knows about?

Thanks in advance.

------------------------------
Have a r0xx0r 1337 day plx!

Share this post


Link to post
Share on other sites
Nevermind. I r teh sex and found the problem (had nothing to do with SDL, I typed glEnable(GL_TEXTURE) and I needed to write: glEnable(GL_TEXTURE_2D)).



------------------------------
Have a r0xx0r 1337 day plx!

Share this post


Link to post
Share on other sites