Skip to main content
gamedev.net
🔒 Locked

So slow!

Started by neonoblivion 25 replies 1.1k views
Original Post
neonoblivion
neonoblivion
I saw a similar problem to this one listed a few days ago, my program is running realy slowly. I read a page on optimizeing opengl code, it talked about droping unnesisery buffery things, and removing slower options such as dithering. I did all these things, and I still get about 5 frames a second with 108 polygons on screen. I have all the polygons facing me so backface culling would not help. When I turn off backbuffering I get a 100% speed boost but thats still not enough (only getting 10fps). Commercial games run at a normal speed on my system so I know thats not the problem. I don''t know if listing my full source in this forum would be apropreit if you think you might be able to help more easly please say so in your replys. Thanks, Klaus
max621
max621
It''d be important for us to know your video card and computer specs.


||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||
||--------------------------||Black Hole Productionshttp://bhp.nydus.netResident expert on stuffmax621@barrysworld.com||--------------------------||
Shag
Shag
Presumably you are running in software mode. I say presumably, because It''s slow even for software.

Check your pixel format - make sure you are selecting a format that can be accelerated in hardware: something like 32 bit colour, 24 z, 8 stencil etc.

Regards

BTW - post your specs nect time!
neonoblivion
neonoblivion
I tryed the 32/24/8 thing but it didn''t work i think its moving a little faster. Here''s the source

  
#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>
#include <GL\glaux.h>
#include <stdio.h>
#include <time.h>

#define width 320
#define height 240
#define bpp 32

#define WINDOW_CLASS_NAME "WINXCLASS"

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

typedef struct ver{
float x,y,z,u,v;
} ver;

typedef struct poly{
int numver;
ver vers[10];
int tex;
} poly;




typedef struct tile{
int numpolys;
poly polys[10];
} tile;




tile tiles[20];

int maph=10,mapw=10;


int map[10][10]={0};


int numpoly=12;

poly polys[100];




float ticks=0,lasttime=0,lasttick=0;

float rx=0,ry=0,rz=0;
float tx,ty,tz;//tranlation variables


char str[100];

float r=.5,g=.5,b=.5,d=.08;


float gu1=0,gv1=1,gu2=1,gv2=1,gu3=1,gv3=0,gu4=0,gv4=0;



bool gp;

GLuint filter;
GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR };
GLuint fogfilter= 0;
GLfloat fogColor[4]= {r, g, b, 1.0f};

bool key[256];



int tex;

HGLRC hrc=NULL;
HDC hdc=NULL;
HWND hwnd=NULL;
HINSTANCE hin;

bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;


GLfloat xrot;
GLfloat yrot;
GLfloat zrot;


GLuint texture[10];


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int init(void);
int gmain(void);
void shutdown(void);
AUX_RGBImageRec *LoadBMP(char *filename);
void ResizeWnd(int Width, int Height);
int loadtex(char *str1,int type,int offset);
void prt(int x,int y,char *str,int r,int g,
int b);


int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow){

MSG msg;
BOOL done=FALSE;

GLuint PixelFormat;
WNDCLASS winclass;


RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;


hin = GetModuleHandle(NULL);
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WndProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hin;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = NULL;
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;

RegisterClass(&winclass);


if (!(hwnd = CreateWindowEx(WS_EX_APPWINDOW,
WINDOW_CLASS_NAME,
"ha ha ha",
WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0,0,
width,height,
NULL,
NULL,
hin,
NULL))){
return(0);
}



DEVMODE dms;
memset(&dms,0,sizeof(dms));
dms.dmSize=sizeof(dms);
dms.dmPelsWidth = width;
dms.dmPelsHeight = height;
dms.dmBitsPerPel = bpp;
dms.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

ChangeDisplaySettings(&dms,CDS_FULLSCREEN);

ShowCursor(FALSE);


static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be

{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor

1, // Version Number

PFD_DRAW_TO_WINDOW | // Format Must Support Window

PFD_SUPPORT_OPENGL | // Format Must Support OpenGL

PFD_DOUBLEBUFFER, // Must Support Double Buffering

PFD_TYPE_RGBA, // Request An RGBA Format

bpp, // Select Our Color Depth

0, 0, 0, 0, 0, 0, // Color Bits Ignored

0, // No Alpha Buffer

0, // Shift Bit Ignored

0, // No Accumulation Buffer

0, 0, 0, 0, // Accumulation Bits Ignored

24, // 16Bit Z-Buffer (Depth Buffer)

0, // No Stencil Buffer

0, // No Auxiliary Buffer

PFD_MAIN_PLANE, // Main Drawing Layer

0, // Reserved

0, 0, 0 // Layer Masks Ignored

};


hdc=GetDC(hwnd);

PixelFormat=ChoosePixelFormat(hdc,&pfd);

SetPixelFormat(hdc,PixelFormat,&pfd);

hrc=wglCreateContext(hdc);

wglMakeCurrent(hdc,hrc);

ShowWindow(hwnd,SW_SHOW);
SetForegroundWindow(hwnd);
SetFocus(hwnd);
ResizeWnd(width, height);
init();

///load texture



////////////////textures

if(loadtex("c:/asphalt.bmp",GL_LINEAR,0)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/corner.bmp",GL_NEAREST,1)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/building.bmp",GL_NEAREST,2)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/sidewalk.bmp",GL_LINEAR,4)==0)
PostMessage(hwnd, WM_DESTROY,0,0);




if(loadtex("c:/ground.bmp",GL_LINEAR,6)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/mountainff.bmp",GL_NEAREST,7)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/mask3.bmp",GL_NEAREST,8)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

if(loadtex("c:/sky3.bmp",GL_LINEAR,9)==0)
PostMessage(hwnd, WM_DESTROY,0,0);

/////////////////textures end




///end load texture


while(1){
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if (msg.message == WM_QUIT)
break;

TranslateMessage(&msg);

DispatchMessage(&msg);
}
//if(WM_ACTIVATE){

if(gmain()==0)
break;
SwapBuffers(hdc);
}
//}



shutdown();


return (msg.wParam);

}







LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){

PAINTSTRUCT ps;
HDC hdc;


switch(msg){

case WM_CREATE:{
return(0);
} break;

case WM_PAINT:{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;



case WM_KEYDOWN:
{
keys[wparam] = 1;
return 0;
}break;

case WM_KEYUP:
{
keys[wparam] = 0;
return 0;
}break;




case WM_DESTROY:{
PostQuitMessage(0);
return(0);
} break;

default:break;

}


return (DefWindowProc(hwnd, msg, wparam, lparam));

}



int init(void){

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glClearColor(fogColor[0],fogColor[1],fogColor[2],fogColor[4]);
glGenTextures(10, texture);

//glEnable(GL_POLYGON_SMOOTH);

//glFogi(GL_FOG_MODE, GL_EXP);

//glFogfv(GL_FOG_COLOR, fogColor);

//glFogf(GL_FOG_DENSITY, d);

//glHint(GL_FOG_HINT, GL_NICEST);

//glFogf(GL_FOG_START, 10.0f);

//glFogf(GL_FOG_END, 25.0f);

//glEnable(GL_FOG);


//glEnable(GL_ALPHA_TEST);

//glEnable(GL_BLEND);

//glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_ALPHA);


glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

glDisable(GL_DITHER);
//memset(map,0,sizeof(int)*50*50);



//tiles


//asphalt

tiles[0].numpolys=1;

tiles[0].polys[0].numver=4;

tiles[0].polys[0].tex=0;

tiles[0].polys[0].vers[0].x=0;
tiles[0].polys[0].vers[0].y=0;
tiles[0].polys[0].vers[0].z=-1;
tiles[0].polys[0].vers[0].u=0;
tiles[0].polys[0].vers[0].v=1;

tiles[0].polys[0].vers[1].x=0;
tiles[0].polys[0].vers[1].y=0;
tiles[0].polys[0].vers[1].z=0;
tiles[0].polys[0].vers[1].u=1;
tiles[0].polys[0].vers[1].v=1;

tiles[0].polys[0].vers[2].x=1;
tiles[0].polys[0].vers[2].y=0;
tiles[0].polys[0].vers[2].z=0;
tiles[0].polys[0].vers[2].u=1;
tiles[0].polys[0].vers[2].v=0;

tiles[0].polys[0].vers[3].x=1;
tiles[0].polys[0].vers[3].y=0;
tiles[0].polys[0].vers[3].z=-1;
tiles[0].polys[0].vers[3].u=0;
tiles[0].polys[0].vers[3].v=0;


//sidewalk corner: top right

tiles[1].numpolys=1;

tiles[1].polys[0].numver=4;

tiles[1].polys[0].tex=1;

tiles[1].polys[0].vers[0].x=0;
tiles[1].polys[0].vers[0].y=0;
tiles[1].polys[0].vers[0].z=-1;
tiles[1].polys[0].vers[0].u=0;
tiles[1].polys[0].vers[0].v=1;

tiles[1].polys[0].vers[1].x=0;
tiles[1].polys[0].vers[1].y=0;
tiles[1].polys[0].vers[1].z=0;
tiles[1].polys[0].vers[1].u=1;
tiles[1].polys[0].vers[1].v=1;

tiles[1].polys[0].vers[2].x=1;
tiles[1].polys[0].vers[2].y=0;
tiles[1].polys[0].vers[2].z=0;
tiles[1].polys[0].vers[2].u=1;
tiles[1].polys[0].vers[2].v=0;

tiles[1].polys[0].vers[3].x=1;
tiles[1].polys[0].vers[3].y=0;
tiles[1].polys[0].vers[3].z=-1;
tiles[1].polys[0].vers[3].u=0;
tiles[1].polys[0].vers[3].v=0;


//sidewalk corner: bottem right

tiles[2].numpolys=1;

tiles[2].polys[0].numver=4;

tiles[2].polys[0].tex=1;

tiles[2].polys[0].vers[0].x=0;
tiles[2].polys[0].vers[0].y=0;
tiles[2].polys[0].vers[0].z=0;
tiles[2].polys[0].vers[0].u=0;
tiles[2].polys[0].vers[0].v=1;

tiles[2].polys[0].vers[1].x=1;
tiles[2].polys[0].vers[1].y=0;
tiles[2].polys[0].vers[1].z=0;
tiles[2].polys[0].vers[1].u=1;
tiles[2].polys[0].vers[1].v=1;

tiles[2].polys[0].vers[2].x=1;
tiles[2].polys[0].vers[2].y=0;
tiles[2].polys[0].vers[2].z=-1;
tiles[2].polys[0].vers[2].u=1;
tiles[2].polys[0].vers[2].v=0;

tiles[2].polys[0].vers[3].x=0;
tiles[2].polys[0].vers[3].y=0;
tiles[2].polys[0].vers[3].z=-1;
tiles[2].polys[0].vers[3].u=0;
tiles[2].polys[0].vers[3].v=0;



//sidewalk corner: bottem left

tiles[3].numpolys=1;

tiles[3].polys[0].numver=4;

tiles[3].polys[0].tex=1;

tiles[3].polys[0].vers[0].x=1;
tiles[3].polys[0].vers[0].y=0;
tiles[3].polys[0].vers[0].z=0;
tiles[3].polys[0].vers[0].u=0;
tiles[3].polys[0].vers[0].v=1;

tiles[3].polys[0].vers[1].x=1;
tiles[3].polys[0].vers[1].y=0;
tiles[3].polys[0].vers[1].z=-1;
tiles[3].polys[0].vers[1].u=1;
tiles[3].polys[0].vers[1].v=1;

tiles[3].polys[0].vers[2].x=0;
tiles[3].polys[0].vers[2].y=0;
tiles[3].polys[0].vers[2].z=-1;
tiles[3].polys[0].vers[2].u=1;
tiles[3].polys[0].vers[2].v=0;

tiles[3].polys[0].vers[3].x=0;
tiles[3].polys[0].vers[3].y=0;
tiles[3].polys[0].vers[3].z=0;
tiles[3].polys[0].vers[3].u=0;
tiles[3].polys[0].vers[3].v=0;


//sidewalk corner: top left

tiles[4].numpolys=1;

tiles[4].polys[0].numver=4;

tiles[4].polys[0].tex=1;

tiles[4].polys[0].vers[0].x=1;
tiles[4].polys[0].vers[0].y=0;
tiles[4].polys[0].vers[0].z=-1;
tiles[4].polys[0].vers[0].u=0;
tiles[4].polys[0].vers[0].v=1;

tiles[4].polys[0].vers[1].x=0;
tiles[4].polys[0].vers[1].y=0;
tiles[4].polys[0].vers[1].z=-1;
tiles[4].polys[0].vers[1].u=1;
tiles[4].polys[0].vers[1].v=1;

tiles[4].polys[0].vers[2].x=0;
tiles[4].polys[0].vers[2].y=0;
tiles[4].polys[0].vers[2].z=0;
tiles[4].polys[0].vers[2].u=1;
tiles[4].polys[0].vers[2].v=0;

tiles[4].polys[0].vers[3].x=1;
tiles[4].polys[0].vers[3].y=0;
tiles[4].polys[0].vers[3].z=0;
tiles[4].polys[0].vers[3].u=0;
tiles[4].polys[0].vers[3].v=0;





//building 1:down

tiles[5].numpolys=2;

tiles[5].polys[0].numver=4;

tiles[5].polys[0].tex=2;

tiles[5].polys[0].vers[0].x=0;//wall

tiles[5].polys[0].vers[0].y=0;
tiles[5].polys[0].vers[0].z=0;
tiles[5].polys[0].vers[0].u=0;
tiles[5].polys[0].vers[0].v=1;

tiles[5].polys[0].vers[1].x=0;
tiles[5].polys[0].vers[1].y=-10;
tiles[5].polys[0].vers[1].z=0;
tiles[5].polys[0].vers[1].u=1;
tiles[5].polys[0].vers[1].v=1;

tiles[5].polys[0].vers[2].x=1;
tiles[5].polys[0].vers[2].y=-10;
tiles[5].polys[0].vers[2].z=0;
tiles[5].polys[0].vers[2].u=1;
tiles[5].polys[0].vers[2].v=0;

tiles[5].polys[0].vers[3].x=1;
tiles[5].polys[0].vers[3].y=0;
tiles[5].polys[0].vers[3].z=0;
tiles[5].polys[0].vers[3].u=0;
tiles[5].polys[0].vers[3].v=0;


tiles[5].polys[1].numver=4;

tiles[5].polys[1].tex=4;

tiles[5].polys[1].vers[0].x=0;//sidewalk

tiles[5].polys[1].vers[0].y=0;
tiles[5].polys[1].vers[0].z=-1;
tiles[5].polys[1].vers[0].u=0;
tiles[5].polys[1].vers[0].v=1;

tiles[5].polys[1].vers[1].x=0;
tiles[5].polys[1].vers[1].y=0;
tiles[5].polys[1].vers[1].z=0;
tiles[5].polys[1].vers[1].u=1;
tiles[5].polys[1].vers[1].v=1;

tiles[5].polys[1].vers[2].x=1;
tiles[5].polys[1].vers[2].y=0;
tiles[5].polys[1].vers[2].z=0;
tiles[5].polys[1].vers[2].u=1;
tiles[5].polys[1].vers[2].v=0;

tiles[5].polys[1].vers[3].x=1;
tiles[5].polys[1].vers[3].y=0;
tiles[5].polys[1].vers[3].z=-1;
tiles[5].polys[1].vers[3].u=0;
tiles[5].polys[1].vers[3].v=0;


//building 1:left

tiles[6].numpolys=2;

tiles[6].polys[0].numver=4;

tiles[6].polys[0].tex=2;

tiles[6].polys[0].vers[0].x=1;//wall

tiles[6].polys[0].vers[0].y=0;
tiles[6].polys[0].vers[0].z=0;
tiles[6].polys[0].vers[0].u=0;
tiles[6].polys[0].vers[0].v=1;

tiles[6].polys[0].vers[1].x=1;
tiles[6].polys[0].vers[1].y=-10;
tiles[6].polys[0].vers[1].z=0;
tiles[6].polys[0].vers[1].u=1;
tiles[6].polys[0].vers[1].v=1;

tiles[6].polys[0].vers[2].x=1;
tiles[6].polys[0].vers[2].y=-10;
tiles[6].polys[0].vers[2].z=-1;
tiles[6].polys[0].vers[2].u=1;
tiles[6].polys[0].vers[2].v=0;

tiles[6].polys[0].vers[3].x=1;
tiles[6].polys[0].vers[3].y=0;
tiles[6].polys[0].vers[3].z=-1;
tiles[6].polys[0].vers[3].u=0;
tiles[6].polys[0].vers[3].v=0;


tiles[6].polys[1].numver=4;

tiles[6].polys[1].tex=4;

tiles[6].polys[1].vers[0].x=0;//sidewalk

tiles[6].polys[1].vers[0].y=0;
tiles[6].polys[1].vers[0].z=0;
tiles[6].polys[1].vers[0].u=0;
tiles[6].polys[1].vers[0].v=1;

tiles[6].polys[1].vers[1].x=1;
tiles[6].polys[1].vers[1].y=0;
tiles[6].polys[1].vers[1].z=0;
tiles[6].polys[1].vers[1].u=1;
tiles[6].polys[1].vers[1].v=1;

tiles[6].polys[1].vers[2].x=1;
tiles[6].polys[1].vers[2].y=0;
tiles[6].polys[1].vers[2].z=-1;
tiles[6].polys[1].vers[2].u=1;
tiles[6].polys[1].vers[2].v=0;

tiles[6].polys[1].vers[3].x=0;
tiles[6].polys[1].vers[3].y=0;
tiles[6].polys[1].vers[3].z=-1;
tiles[6].polys[1].vers[3].u=0;
tiles[6].polys[1].vers[3].v=0;



//building 1:up

tiles[7].numpolys=2;

tiles[7].polys[0].numver=4;

tiles[7].polys[0].tex=2;

tiles[7].polys[0].vers[0].x=1;//wall

tiles[7].polys[0].vers[0].y=0;
tiles[7].polys[0].vers[0].z=-1;
tiles[7].polys[0].vers[0].u=0;
tiles[7].polys[0].vers[0].v=1;

tiles[7].polys[0].vers[1].x=1;
tiles[7].polys[0].vers[1].y=-10;
tiles[7].polys[0].vers[1].z=-1;
tiles[7].polys[0].vers[1].u=1;
tiles[7].polys[0].vers[1].v=1;

tiles[7].polys[0].vers[2].x=0;
tiles[7].polys[0].vers[2].y=-10;
tiles[7].polys[0].vers[2].z=-1;
tiles[7].polys[0].vers[2].u=1;
tiles[7].polys[0].vers[2].v=0;

tiles[7].polys[0].vers[3].x=0;
tiles[7].polys[0].vers[3].y=0;
tiles[7].polys[0].vers[3].z=-1;
tiles[7].polys[0].vers[3].u=0;
tiles[7].polys[0].vers[3].v=0;


tiles[7].polys[1].numver=4;

tiles[7].polys[1].tex=4;

tiles[7].polys[1].vers[0].x=1;//sidewalk

tiles[7].polys[1].vers[0].y=0;
tiles[7].polys[1].vers[0].z=0;
tiles[7].polys[1].vers[0].u=0;
tiles[7].polys[1].vers[0].v=1;

tiles[7].polys[1].vers[1].x=1;
tiles[7].polys[1].vers[1].y=0;
tiles[7].polys[1].vers[1].z=-1;
tiles[7].polys[1].vers[1].u=1;
tiles[7].polys[1].vers[1].v=1;

tiles[7].polys[1].vers[2].x=0;
tiles[7].polys[1].vers[2].y=0;
tiles[7].polys[1].vers[2].z=-1;
tiles[7].polys[1].vers[2].u=1;
tiles[7].polys[1].vers[2].v=0;

tiles[7].polys[1].vers[3].x=0;
tiles[7].polys[1].vers[3].y=0;
tiles[7].polys[1].vers[3].z=0;
tiles[7].polys[1].vers[3].u=0;
tiles[7].polys[1].vers[3].v=0;



//building 1:right

tiles[8].numpolys=2;

tiles[8].polys[0].numver=4;

tiles[8].polys[0].tex=2;

tiles[8].polys[0].vers[0].x=0;//wall

tiles[8].polys[0].vers[0].y=0;
tiles[8].polys[0].vers[0].z=0;
tiles[8].polys[0].vers[0].u=0;
tiles[8].polys[0].vers[0].v=1;

tiles[8].polys[0].vers[1].x=0;
tiles[8].polys[0].vers[1].y=-10;
tiles[8].polys[0].vers[1].z=0;
tiles[8].polys[0].vers[1].u=1;
tiles[8].polys[0].vers[1].v=1;

tiles[8].polys[0].vers[2].x=0;
tiles[8].polys[0].vers[2].y=-10;
tiles[8].polys[0].vers[2].z=-1;
tiles[8].polys[0].vers[2].u=1;
tiles[8].polys[0].vers[2].v=0;

tiles[8].polys[0].vers[3].x=0;
tiles[8].polys[0].vers[3].y=0;
tiles[8].polys[0].vers[3].z=-1;
tiles[8].polys[0].vers[3].u=0;
tiles[8].polys[0].vers[3].v=0;


tiles[8].polys[1].numver=4;

tiles[8].polys[1].tex=4;

tiles[8].polys[1].vers[0].x=1;//sidewalk

tiles[8].polys[1].vers[0].y=0;
tiles[8].polys[1].vers[0].z=-1;
tiles[8].polys[1].vers[0].u=0;
tiles[8].polys[1].vers[0].v=1;

tiles[8].polys[1].vers[1].x=0;
tiles[8].polys[1].vers[1].y=0;
tiles[8].polys[1].vers[1].z=-1;
tiles[8].polys[1].vers[1].u=1;
tiles[8].polys[1].vers[1].v=1;

tiles[8].polys[1].vers[2].x=0;
tiles[8].polys[1].vers[2].y=0;
tiles[8].polys[1].vers[2].z=0;
tiles[8].polys[1].vers[2].u=1;
tiles[8].polys[1].vers[2].v=0;

tiles[8].polys[1].vers[3].x=1;
tiles[8].polys[1].vers[3].y=0;
tiles[8].polys[1].vers[3].z=0;
tiles[8].polys[1].vers[3].u=0;
tiles[8].polys[1].vers[3].v=0;






//end tiles







return(0);
}

void shutdown(void){
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
wglMakeCurrent(NULL,NULL);
if(hrc){
wglDeleteContext(hrc);
hrc=NULL;
}
if(hdc){
ReleaseDC(hwnd,hdc);
hdc=NULL;
}
if(hwnd){
DestroyWindow(hwnd);
hwnd=NULL;
}

UnregisterClass("WINDOWS_CLASS_NAME",hin);
hin=NULL;
}




int gmain(void){

int mapxy=0;

ticks=(clock()-lasttime)/CLK_TCK;
lasttime=(float)clock();
sprintf(str,"The frame rate is %f.",ticks);
prt(0,0,str,200,0,0);

if(ticks==0)
ticks=lasttick;
else
lasttick=ticks;


if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE)){
PostMessage(hwnd, WM_DESTROY,0,0);
return(0);
}

if(KEY_DOWN(VK_UP)){
if(rx>0)
rx-=.5;//(1/ticks)*.1;

else
rx+=360;//360+((1/ticks)*.1);

}

if(KEY_DOWN(VK_DOWN)){

if(rx<360)
rx+=.5;//(1/ticks)*.1;

else
rx-=360;//360-((1/ticks)*.1);



}

if(KEY_DOWN(VK_LEFT)){
if(ry<360)
ry+=.5;//(1/ticks)*.1;

else
ry-=360;//360-((1/ticks)*.1);

}

if(KEY_DOWN(VK_RIGHT)){
if(ry>0)
ry-=.5;//(1/ticks)*.1;

else
ry+=360;//360+((1/ticks)*.1);

}

if(keys[''A'']){
if(rz<360)
rz+=.5;//(1/ticks)*.1;

else
rz-=360;//360-((1/ticks)*.1);

}
if(keys[''Z'']){
if(rz>0)
rz-=.5;//(1/ticks)*.1;

else
rz+=360;//360+((1/ticks)*.1);

}

if(keys[''H'']){//left

tx+=.5;
}
if(keys[''B'']){//Right

tx-=.5;
}
if(keys[''J'']){//up

ty+=.5;
}
if(keys[''N'']){//down

ty-=.5;
}

if(keys[''K'']){//forward

tz+=.5;
}
if(keys[''M'']){//backward

tz-=.5;
}


glClear(/*GL_COLOR_BUFFER_BIT |*/ GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(-190,1.0f,0.0f,0.0f);
glRotatef(rx,1.0f,0.0f,0.0f);
glRotatef(ry,0.0f,1.0f,0.0f);
glRotatef(rz,0.0f,0.0f,1.0f);
glTranslatef(tx,3+ty,tz);


for(int y=0;y<maph;y++){
for(int x=0;x<mapw;x++){
mapxy=map[y][x];
for(int index=0;index<tiles[8/*mapxy*/].numpolys;index++){
glBindTexture(GL_TEXTURE_2D,
texture[tiles[8/*mapxy*/].polys[index].tex]);

glBegin(GL_POLYGON);


//for(int index2=0;index2<tiles[8/*mapxy*/].polys[index].numver;index2++){

glTexCoord2f(tiles[8/*mapxy*/].polys[index].vers[0].u,
tiles[8/*mapxy*/].polys[index].vers[0].v);

glVertex3f(tiles[8/*mapxy*/].polys[index].vers[0].x,
tiles[8/*mapxy*/].polys[index].vers[0].y,
tiles[8/*mapxy*/].polys[index].vers[0].z);


glTexCoord2f(tiles[8/*mapxy*/].polys[index].vers[1].u,
tiles[8/*mapxy*/].polys[index].vers[1].v);

glVertex3f(tiles[8/*mapxy*/].polys[index].vers[1].x,
tiles[8/*mapxy*/].polys[index].vers[1].y,
tiles[8/*mapxy*/].polys[index].vers[1].z);


glTexCoord2f(tiles[8/*mapxy*/].polys[index].vers[2].u,
tiles[8/*mapxy*/].polys[index].vers[2].v);

glVertex3f(tiles[8/*mapxy*/].polys[index].vers[2].x,
tiles[8/*mapxy*/].polys[index].vers[2].y,
tiles[8/*mapxy*/].polys[index].vers[2].z);


glTexCoord2f(tiles[8/*mapxy*/].polys[index].vers[3].u,
tiles[8/*mapxy*/].polys[index].vers[3].v);

glVertex3f(tiles[8/*mapxy*/].polys[index].vers[3].x,
tiles[8/*mapxy*/].polys[index].vers[3].y,
tiles[8/*mapxy*/].polys[index].vers[3].z);
// }
glEnd();
}
}

}

//glEnable(GL_BLEND);

/*glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);

glTexCoord2f(0,1);
glVertex3f(-11,0,20);

glTexCoord2f(1,1);
glVertex3f(11,0,20);

glTexCoord2f(1,0);
glVertex3f(11,7,20);

glTexCoord2f(0,0);
glVertex3f(-11,7,20);

glEnd();






glBlendFunc(GL_ONE, GL_ONE);

glBindTexture(GL_TEXTURE_2D, texture[1]);

glBegin(GL_QUADS);

glTexCoord2f(0,1);
glVertex3f(-11,0,20);

glTexCoord2f(1,1);
glVertex3f(11,0,20);

glTexCoord2f(1,0);
glVertex3f(11,7,20);

glTexCoord2f(0,0);
glVertex3f(-11,7,20);

glEnd();

*/

//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

//glColor4f(1.0,1.0,1.0,0.7);




//////////////////////////////////////////////////////////////////////////////







glBindTexture(GL_TEXTURE_2D, texture[6]);
glBegin(GL_QUADS);

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

glTexCoord2f(1,1);
glVertex3f(101,-1,101);

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

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

glEnd();





///////////////////////////////////////////////////////////////

//glDisable(GL_BLEND);


/* if(gu1>1){
gu1-=1;//.001;
gu2-=1;//.001;
gu3-=1;//.001;
gu4-=1;//.001;
}
else if(gu2>1){
gu1-=1;//.001;
gu2-=1;//.001;
gu3-=1;//.001;
gu4-=1;//.001;
}
else if(gu3>1){
gu1-=1;//.001;
gu2-=1;//.001;
gu3-=1;//.001;
gu4-=1;//.001;
}
else if(gu4>1){
gu1-=1;//.001;
gu2-=1;//.001;
gu3-=1;//.001;
gu4-=1;//.001;
}
else{
gu1+=.0001;
gu2+=.0001;
gu3+=.0001;
gu4+=.0001;
}

*/
//glColor3f(1,.5,.5);





//////////////////////////////////////////////////////////////////////////





///*

glBindTexture(GL_TEXTURE_2D, texture[9]);
glBegin(GL_QUADS);

glTexCoord2f(gu1,gv1);
glVertex3f(-100,-60,100);

glTexCoord2f(gu2,gv2);
glVertex3f(100,-60,100);

glTexCoord2f(gu3,gv3);
glVertex3f(100,-60,-100);

glTexCoord2f(gu4,gv4);
glVertex3f(-100,-60,-100);


glEnd();

int hay=-60,hinc=70;




/*
glEnable(GL_BLEND);

glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBindTexture(GL_TEXTURE_2D, texture[8]);
glBegin(GL_QUADS);

glTexCoord2f(0,.99);
glVertex3f(-36,hay,96);

glTexCoord2f(1,.99);
glVertex3f(36,hay,96);

glTexCoord2f(1,0);
glVertex3f(36,hay+hinc,96);

glTexCoord2f(0,0);
glVertex3f(-36,hay+hinc,96);


glTexCoord2f(0,.99);
glVertex3f(36,hay,96);

glTexCoord2f(1,.99);
glVertex3f(96,hay,36);

glTexCoord2f(1,0);
glVertex3f(96,hay+hinc,36);

glTexCoord2f(0,0);
glVertex3f(36,hay+hinc,96);


glTexCoord2f(0,.99);
glVertex3f(96,hay,36);

glTexCoord2f(1,.99);
glVertex3f(96,hay,-36);

glTexCoord2f(1,0);
glVertex3f(96,hay+hinc,-36);

glTexCoord2f(0,0);
glVertex3f(96,hay+hinc,36);


glTexCoord2f(0,.99);
glVertex3f(96,hay,-36);

glTexCoord2f(1,.99);
glVertex3f(36,hay,-96);

glTexCoord2f(1,0);
glVertex3f(36,hay+hinc,-96);

glTexCoord2f(0,0);
glVertex3f(96,hay+hinc,-36);


glTexCoord2f(0,.99);
glVertex3f(36,hay,-96);

glTexCoord2f(1,.99);
glVertex3f(-36,hay,-96);

glTexCoord2f(1,0);
glVertex3f(-36,hay+hinc,-96);

glTexCoord2f(0,0);
glVertex3f(36,hay+hinc,-96);


glTexCoord2f(0,.99);
glVertex3f(-36,hay,-96);

glTexCoord2f(1,.99);
glVertex3f(-96,hay,-36);

glTexCoord2f(1,0);
glVertex3f(-96,hay+hinc,-36);

glTexCoord2f(0,0);
glVertex3f(-36,hay+hinc,-96);


glTexCoord2f(0,.99);
glVertex3f(-96,hay,-36);

glTexCoord2f(1,.99);
glVertex3f(-96,hay,36);

glTexCoord2f(1,0);
glVertex3f(-96,hay+hinc,36);

glTexCoord2f(0,0);
glVertex3f(-96,hay+hinc,-36);


glTexCoord2f(0,.99);
glVertex3f(-96,hay,36);

glTexCoord2f(1,.99);
glVertex3f(-36,hay,96);

glTexCoord2f(1,0);
glVertex3f(-36,hay+hinc,96);

glTexCoord2f(0,0);
glVertex3f(-96,hay+hinc,36);



glEnd();








glBlendFunc(GL_ONE, GL_ONE);
*/



//////////////////////////////////////////////////////////////////////////






///*



glBindTexture(GL_TEXTURE_2D, texture[7]);

glBegin(GL_QUADS);

glTexCoord2f(0,.99);
glVertex3f(-36,hay,96);

glTexCoord2f(1,.99);
glVertex3f(36,hay,96);

glTexCoord2f(1,0);
glVertex3f(36,hay+hinc,96);

glTexCoord2f(0,0);
glVertex3f(-36,hay+hinc,96);


glTexCoord2f(0,.99);
glVertex3f(36,hay,96);

glTexCoord2f(1,.99);
glVertex3f(96,hay,36);

glTexCoord2f(1,0);
glVertex3f(96,hay+hinc,36);

glTexCoord2f(0,0);
glVertex3f(36,hay+hinc,96);


glTexCoord2f(0,.99);
glVertex3f(96,hay,36);

glTexCoord2f(1,.99);
glVertex3f(96,hay,-36);

glTexCoord2f(1,0);
glVertex3f(96,hay+hinc,-36);

glTexCoord2f(0,0);
glVertex3f(96,hay+hinc,36);


glTexCoord2f(0,.99);
glVertex3f(96,hay,-36);

glTexCoord2f(1,.99);
glVertex3f(36,hay,-96);

glTexCoord2f(1,0);
glVertex3f(36,hay+hinc,-96);

glTexCoord2f(0,0);
glVertex3f(96,hay+hinc,-36);


glTexCoord2f(0,.99);
glVertex3f(36,hay,-96);

glTexCoord2f(1,.99);
glVertex3f(-36,hay,-96);

glTexCoord2f(1,0);
glVertex3f(-36,hay+hinc,-96);

glTexCoord2f(0,0);
glVertex3f(36,hay+hinc,-96);


glTexCoord2f(0,.99);
glVertex3f(-36,hay,-96);

glTexCoord2f(1,.99);
glVertex3f(-96,hay,-36);

glTexCoord2f(1,0);
glVertex3f(-96,hay+hinc,-36);

glTexCoord2f(0,0);
glVertex3f(-36,hay+hinc,-96);


glTexCoord2f(0,.99);
glVertex3f(-96,hay,-36);

glTexCoord2f(1,.99);
glVertex3f(-96,hay,36);

glTexCoord2f(1,0);
glVertex3f(-96,hay+hinc,36);

glTexCoord2f(0,0);
glVertex3f(-96,hay+hinc,-36);


glTexCoord2f(0,.99);
glVertex3f(-96,hay,36);

glTexCoord2f(1,.99);
glVertex3f(-36,hay,96);

glTexCoord2f(1,0);
glVertex3f(-36,hay+hinc,96);

glTexCoord2f(0,0);
glVertex3f(-96,hay+hinc,36);



glEnd();




//////////////////////////////////////////
/**/







// glDisable(GL_BLEND);


glTranslatef(0.0f,0.0f,0.0f);

//sprintf(str,"The frame rate is %f.",ticks);

//prt(0,0,str,200,0,0);



return(1);
}



void ResizeWnd(int Width, int Height){
GLfloat fAspect;
if (!Height)
Height = 1;
glViewport(0, 0, Width, Height);
fAspect = (float)Width/(float)Height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, fAspect, 1.0, 400.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}



int loadtex(char *str1,int type,int offset){

AUX_RGBImageRec *tex;
memset(tex,0,sizeof(void *)*1);
if(!(tex=LoadBMP(str1)))
return(0);



// for(int index=0;index<10;index++){

glBindTexture(GL_TEXTURE_2D, texture[offset]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, tex->sizeX,
tex->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
tex->data);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,type);//GL_NEAREST );

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,type);//GL_NEAREST );

// }


// for(int index2=0;index2<10;index2++){

if(tex){
if(tex->data){
free(tex->data);
}
free(tex);
}

// }

return(1);
}



AUX_RGBImageRec *LoadBMP(char *filename){
FILE *file;
if(!(file=fopen(filename,"r")))
return(0);
fclose(file);
return auxDIBImageLoad(filename);
}



void prt(int x,int y,char *str,int r,int g,int b){

SetBkMode(hdc,TRANSPARENT);

SetTextColor(hdc,RGB(r,g,b));
SetBkColor(hdc,RGB(0,0,0));

TextOut(hdc,x,y,str,strlen(str));

}




some of the polygons are commented out, and the loop is just acting as a stand-in for a tile system I am working on.


silvermace
silvermace
no offence but thats messy code =)
ok, from what i can see (i'll look harder after dinner)
- ur calling glVertex3f() while using integers
int->float is on of the the slowest type conversions there is,
also the constants aren't being compiled using the .f thingo
eg. usr using glVertex3f(100,100,0); it SHOULD be glVertex3f(100.f,100.f,0.f) or glVertex3i(...)

ESPECIALY for glTexCoord2f man!

- if ur using VC, pres Ctrl+H and replace glVertex3f with glVertex3i.

- use display lists dude !!!

k, im off to eat, i'll look harder when i get back, Cya, hope that helps

[edited by - silvermace on June 11, 2002 3:56:40 AM]
Janju
Janju
Have you checked out NeHe s stuff. Do his tutorials run faster on your system?

[edited by - Jonus on June 11, 2002 4:16:02 AM]
Ysaneya
Ysaneya
Try a 16-bits color mode with a 16-bits ZBuffer. Make sure you''re not running in software (use glGetString(GL_RENDERER); if you see Microsoft Generic, you''re in software).

Y.
neonoblivion
neonoblivion
Thanks for all your replys.

I was originaly running in 16/16 mode so Idon''t think thats my problem.

Silvermace, I cut out the code that was using the ints and it still runs realy slowly, I got couple more frames a second but it was not that muck better.

How do I use glGetString(GL_RENDERER)? What kind of variable do I shove it in to?

Klaus
weasalmongler
weasalmongler

  
char *filename = glGetString(GL_RENDERER);
//and print out

logFile.Write("%s", filename);


Something along those lines .

- Weasalmongler
Prosper/LOADED
Prosper/LOADED
What are your textures sizes ? Since you don''t seem to use mipmaping, using big textures when drawing little polys may mess up your video card cache and give you poor performance.
AIRmichael
AIRmichael
tiles[8/*mapxy*/].polys[index].vers[0].x
doesnt this kinda run slow? Btw add some // tags in front of the render scene, to check if thats the prob or not.

IndirectX
IndirectX
Try using timeGetTime or QueryPerformanceCounter instead of clock. And your code is a pain to look at.
---visit #directxdev on afternet <- not just for directx, despite the name
CaptainJester
CaptainJester
Every call to glBindTextrue() is a big performance hit. You have about 10 textures going there and oyu change them for every poly. This can cause your video card to dump the texture cash and reload everything. Try to load each texture once and call all the polys that use it before switching to the next one.

You use GL_POLYGON and GL_QUADS a lot. They are the slowest primatives to use. Try to use GL_TRIANGLE or GL_TRIANGLE_STRIP if you can.

Build all your primatives using display lists. They are precomputed and display much much faster than drawing your polys manually every loop. You can also bind your texture when you build your list if you know that it is not going to change while the program is running.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Shag
Shag
I think you''ll find it''s maybe your FPS counter that''s completely wrong - don''t use clock(), (use GetTickCount() or similar)

Also, don''t use TextOut to display the frame rate. an easy way (for your purposes) is not to run in fullscreen mode, and use SetWindowText to display FPS in the title bar - it''ll at least verify what the actual frame rate is.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.