OpenGL ES -- SDL on iPhone -- Cannot render a triangle

Hi,

so far, I have unsuccessfully tried to render a single triangle on my iPhone. I
have taken the “fireworks” sample by Holmes Futrell and it works like a charm.
But then I modified the program a little to “simply” render a single triangle –
and no matter what I do, the simulator won’t display a thing. Do you have an
idea what could be wrong? Thanks a lot for your help!

Philipp

#include “SDL.h”
#include “SDL_opengles.h”

#include <math.h>
#include <time.h>

void drawBody() {
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
const GLfloat triVertices[] = {
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f
};
glVertexPointer(3, GL_FLOAT, 0, triVertices);
glDrawArrays(GL_TRIANGLES, 0, 3);

SDL_RenderPresent();

}

int
main(int argc, char *argv[])
{

SDL_WindowID windowID;
Uint32 startFrame;    
Uint32 endFrame;      
Uint32 delay;         
int done;             

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  exit(1);
}

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

windowID = SDL_CreateWindow(NULL, 0, 0, 320, 480,
											SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
														SDL_WINDOW_BORDERLESS);
SDL_CreateRenderer(windowID, 0, 0);
		
glEnableClientState(GL_VERTEX_ARRAY);	

done = 0;
while (!done) {
	startFrame = SDL_GetTicks();
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			done = 1;
		}
	}
	drawBody();
	endFrame = SDL_GetTicks();
	
	delay = 40 - (endFrame - startFrame);
	if (delay > 40) {
		delay = 40;
	}
	if (delay > 0) {
		SDL_Delay(delay);
	}
}

SDL_Quit();

return 0;

}

Hi,

shouldn’t you be setting your projection and view matrixes?

Regards,
PauloOn Fri, Jan 9, 2009 at 12:53 PM, Philipp Bouillon < Philipp.Bouillon at gmail.com> wrote:

Hi,

so far, I have unsuccessfully tried to render a single triangle on my
iPhone. I
have taken the “fireworks” sample by Holmes Futrell and it works like a
charm.
But then I modified the program a little to “simply” render a single
triangle –
and no matter what I do, the simulator won’t display a thing. Do you have
an
idea what could be wrong? Thanks a lot for your help!

Philipp

#include “SDL.h”
#include “SDL_opengles.h”

#include <math.h>
#include <time.h>

void drawBody() {
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
const GLfloat triVertices[] = {
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f
};
glVertexPointer(3, GL_FLOAT, 0, triVertices);
glDrawArrays(GL_TRIANGLES, 0, 3);

   SDL_RenderPresent();

}

int
main(int argc, char *argv[])
{

   SDL_WindowID windowID;
   Uint32 startFrame;
   Uint32 endFrame;
   Uint32 delay;
   int done;

   if (SDL_Init(SDL_INIT_VIDEO) < 0) {
     exit(1);
   }

   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
   SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
   SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

   windowID = SDL_CreateWindow(NULL, 0, 0, 320, 480,

               SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |

                                       SDL_WINDOW_BORDERLESS);
   SDL_CreateRenderer(windowID, 0, 0);

   glEnableClientState(GL_VERTEX_ARRAY);

   done = 0;
   while (!done) {
           startFrame = SDL_GetTicks();
           SDL_Event event;
           while (SDL_PollEvent(&event)) {
                   if (event.type == SDL_QUIT) {
                           done = 1;
                   }
           }
           drawBody();
           endFrame = SDL_GetTicks();

           delay = 40 - (endFrame - startFrame);
           if (delay > 40) {
                   delay = 40;
           }
           if (delay > 0) {
                   SDL_Delay(delay);
           }
   }

   SDL_Quit();

   return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Indeed. Ouch :).
Thanks.>

Hi,shouldn’t you be setting your projection and view matrixes?Regards,Paulo