Oh, also what other types of syntax can be used in static libraries? structs? classes? inheritance? templates?
Oh, also what other types of syntax can be used in static libraries? structs? classes? inheritance? templates?
I am trying to make a static library using Code::Blocks and when I make a new static library project it generates a cpp file with functions encased with extern "C"
I am just wondering if this is necessary or if I can write the functions in normal c++ as well.
Thank you!
Don't you just hate it when you bite off more than you can chew? I am in Grade 12 taking a first year university programming course, I guess I will have to wait until later to learn some of the techniques on how to do this :(. For now I will work on a slow but functional version that I already have (it saves a set of CollisionCheck unions that can be spheres, or planes, then checks each one) Thanks for your help!
I have this problem:
struct Position
{
float x;
float y;
float z;
};
bool CheckCollision(Position *vertices, int numvertices, Position start, Position end)
{
//return true if there was NOT a collision with the polygon defined by the vertices and the vector defined by the two positions.
}
I dont even know where to begin, I thought of stepping through the vector from start to end in small increments, but that would be slow and might pass right through the polygon sans interference. Any hints?
Thanks, but how exactly do I do this? I am used to C++, but I do have MASM and CV for writing assembly when necessary. Is there any way I could create something like a batch command to convert an ASM program into binary representation?
VICTORY!!! THANK YOU FOR YOUR HELP!!! I finally got fed up messing around with components of vectors, so I just changed Move to take distance, yaw, pitch, then I just used the resulting vector and my knowledge of solving the components of 3D vectors and came up with a working function!
Oh and I renamed my rotation variables, here you can read them better:
OpenGLInstance &OpenGLInstance::Move(float rl, float fb, float z)
{
pos.x-=(float)sin(DEGTORAD(pos.yaw-90.0f))*rl;
pos.z-=(float)cos(DEGTORAD(pos.yaw-90.0f))*rl;
pos.x-=(float)sin(DEGTORAD(pos.yaw))*fb;
pos.z-=(float)cos(DEGTORAD(pos.yaw))*fb;
pos.y+=z;
return *this;
}
OpenGLInstance &OpenGLInstance::Rotate(float rl, float ud, float cc)
{
pos.roll+=cc;
pos.yaw+=rl;
pos.pitch+=ud;
return *this;
}
ok, its starting to kinda work, but my movement is... weird, i think that its not taking my direction into account correctly.
I would just like to know how x86 ASM instructions are translated into binary. EG: mov al,061h
becomes 10110000 01100001
Ok, not working. I swapped the pos.h and pos.t as you suggested.
Mouse functions:
OpenGLInstance &OpenGLInstance::Mouse(int x, int y)
{
RECT windim;
GetWindowRect(hWnd,&windim);
SetCursorPos(x+windim.left,y+windim.top);
return *this;
}
OpenGLInstance &OpenGLInstance::Mouse(int *x, int *y)
{
if (x==NULL|y==NULL)
return *this;
POINT *temp;
GetCursorPos(temp);
*x=temp->x;
*y=temp->y;
return *this;
}
Redraw and Update functions:
OpenGLInstance &OpenGLInstance::Update()
{
SwapBuffers(hDC);
MSG temp;
PeekMessage(&temp,NULL,0,0,PM_REMOVE);
TranslateMessage(&temp);
DispatchMessage(&temp);
//wait off to force the fps
LARGE_INTEGER tmp;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&tmp);
double deltatime=((double)(tmp.QuadPart-lastframe.QuadPart)/(double)freq.QuadPart)*(double)1000.0;
double frametime=1000.0/(double)window.fps;
if (deltatime<frametime)
Sleep(frametime-deltatime);
QueryPerformanceCounter(&lastframe);
return *this;
}
OpenGLInstance &OpenGLInstance::Redraw()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(pos.t,1,0,0);
glRotatef(pos.v,0,1,0);
glRotatef(pos.h,0,0,1);
glTranslatef(-pos.x,-pos.y,pos.z);
return *this;
}
test.cpp:
#define SUPPRESS_VBOS
#include "3dglgui.h"
int main()
{
GL.Init("TEST",500,500,32,false,0,0);
if (GL.ERRORCODE)
{
return GL.ERRORCODE;
}
glModel model;
model.Vertex( 0, 1, 0, 0, 0);
model.Vertex(-1,-1, 0, 1, 1);
model.Vertex( 1,-1, 0, 1, 0);
model.Texture("RANDOMTEST.bmp",true);
int dx=0, dy=0;
do{
GL.Redraw();
//GL.Mouse(&dx,&dy);//this is commented out because it causes a sigseg... why?
//GL.Rotate(dx-50,dy-50,0).Mouse(50,50);//will this work if the above works?
glTranslatef(1,0,-6);
if (GL.window.key[VK_UP])
GL.Move(0,0,0.1);
if (GL.window.key[VK_DOWN])
GL.Move(0,0,-0.1);
if (GL.window.key[VK_RIGHT])
GL.Move(0.1,0,0);
if (GL.window.key[VK_LEFT])
GL.Move(-0.1,0,0);
if (GL('a'))
GL.Rotate(1,0,0);
if (GL('e'))
GL.Rotate(-1,0,0);
if (GL(','))
GL.Rotate(0,1,0);
if (GL('o'))
GL.Rotate(0,-1,0);
GL.Draw(model);
GL.Update();
}while(!GL.window.key[VK_ESCAPE]);
GL.Kill();
return 0;
}
It all works in the state above, but when I press the ,aoe keys (Dvorak equivalent of WASD) nothing happens. The Mouse based lines cause a SIGSEG. I kinda need both to work.
The problem must be in my Rotation and Motion. Here are the related functions:
OpenGLInstance &OpenGLInstance::Move(float rl, float fb, float z)
{
if (rl>0)
{
pos.x-=(float)sin(DEGTORAD(pos.h-90.0f))*rl;
pos.y-=(float)cos(DEGTORAD(pos.h-90.0f))*rl;
}
else
{
pos.x+=(float)sin(DEGTORAD(pos.h+90.0f))*rl;
pos.y+=(float)cos(DEGTORAD(pos.h+90.0f))*rl;
}
pos.x-=(float)sin(DEGTORAD(pos.h))*fb;
pos.y-=(float)cos(DEGTORAD(pos.h))*fb;
pos.z+=z;
return *this;
}
OpenGLInstance &OpenGLInstance::Rotate(float rl, float ud, float cc)
{
pos.h+=rl;
pos.v+=ud;
pos.t+=cc;
return *this;
}
OpenGLInstance &OpenGLInstance::Update()
{
glRotatef(pos.h,1,0,0);
glRotatef(pos.v,0,1,0);
glRotatef(pos.t,0,0,1);
glTranslatef(-pos.x,-pos.y,-pos.z);
SwapBuffers(hDC);
MSG temp;
PeekMessage(&temp,NULL,0,0,PM_REMOVE);
TranslateMessage(&temp);
DispatchMessage(&temp);
//wait off to force the fps
LARGE_INTEGER tmp;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&tmp);
double deltatime=((double)(tmp.QuadPart-lastframe.QuadPart)/(double)freq.QuadPart)*(double)1000.0;
double frametime=1000.0/(double)window.fps;
if (deltatime<frametime)
Sleep(frametime-deltatime);
QueryPerformanceCounter(&lastframe);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
return *this;
}
*facepalm* I cant believe I missed it! The problem was in my Init() function! I never created a device context! I just had to add hRC=wglCreateContext(hDC);
. I still cant get my Model class to draw thought, I just get a blank black screen. Here is my new test code:
#define SUPPRESS_VBOS
#include "3dglgui.h"
int main()
{
GL.Init("TEST",500,500,32,false,0,0);
if (GL.ERRORCODE)
{
return GL.ERRORCODE;
}
glModel model;
model.Vertex(0,0,0,0,0);
model.Vertex(1,1,1,1,1);
model.Vertex(1,0,1,1,0);
model.Texture("RANDOMTEST.bmp",true);
do{
if (GL.window.key[VK_UP])
GL.Move(0,0.1f,0);
if (GL.window.key[VK_DOWN])
GL.Move(0,-0.1f,0);
GL.Draw(model);
GL.Update();
}while(!GL.window.key[VK_ESCAPE]);
GL.Kill();
return 0;
}
Here is more of my code:
Test.cpp:
#define SUPPRESS_VBOS
#include "3dglgui.h"
int main()
{
GL.Init("TEST",500,500,false,0,0);
if (GL.ERRORCODE)
{
return GL.ERRORCODE;
}
glModel model;
model.Vertex(0,0,0,0,0);
model.Vertex(1,1,1,1,1);
model.Vertex(1,0,1,1,0);
model.Texture("RANDOMTEST.bmp",true);
do{
GL.Draw(model);
GL.Update();
}while(!GL.window.key[VK_ESCAPE]);
GL.Kill();
return 0;
}
Update Function:
OpenGLInstance &OpenGLInstance::Update()
{
SwapBuffers(hDC);
MSG temp;
PeekMessage(&temp,NULL,0,0,PM_REMOVE);
TranslateMessage(&temp);
DispatchMessage(&temp);
//wait off to force the fps
LARGE_INTEGER tmp;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&tmp);
double deltatime=((double)(tmp.QuadPart-lastframe.QuadPart)/(double)freq.QuadPart)*(double)1000.0;
double frametime=1000.0/(double)window.fps;
if (deltatime<frametime)
Sleep(frametime-deltatime);
QueryPerformanceCounter(&lastframe);
return *this;
}
Ok, I tried everything to get VBOs to work and failed, so I moved on to making my header backwards compatible using display lists (since they worked for me at one point) the issue is that I am still failing. Here is the added section of code:
#ifdef SUPPRESS_VBOS//no VBOs
glModel &glModel::Compile()//uses display lists
{
if (numv<3)
return *this;
model=glGenLists(1);
glNewList(model,GL_COMPILE);
glBegin(GL_TRIANGLES);
for (int i=0; i<numv; i++)
{
glTexCoord2f(vars[i].text[0],vars[i].text[1]);
glVertex3f(vars[i].vert[0],vars[i].vert[1],vars[i].vert[2]);
glNormal3f(vars[i].norm[0],vars[i].norm[1],vars[i].norm[2]);
}
glEnd();
glEndList();
COMPILED_ID=id;
return *this;
}
glModel &glModel::Draw()
{
if (texture==0){return *this;}
if (COMPILED_ID!=id){Compile();}
glCallList(model);
return *this;
}
#else
glModel &glModel::Compile()
{
if (numv<3)
return *this;
glGenBuffers(1,&model);
glBindBuffer(GL_ARRAY_BUFFER,model);
glBufferData(GL_ARRAY_BUFFER, numv*sizeof(glVertexStructure), vars, GL_STATIC_DRAW);
COMPILED_ID=id;
return *this;
}
glModel &glModel::Draw()
{
if (texture==0){return *this;}
if (COMPILED_ID!=id){Compile();}//1st sigseg comes from here
int numt=numv-numv%3;
if (numt==0)
return *this;
glBindBuffer(GL_ARRAY_BUFFER,model);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(glVertexStructure),0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,sizeof(glVertexStructure),&(vars[0].text[0]));
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,sizeof(glVertexStructure),&(vars[0].norm[0]));
glDrawArrays(GL_TRIANGLES, 0, numt);
#endif
return *this;
}
#endif
But I am still getting a blank window which requires using the Task Manager to kill. What am I doing wrong?
You have a point there... I just need Math.XXX() because im working with somebody that learnt Java before C++. I guess I can just use the cmath functions in my Math class.
Ill try that.
Ok, another question then, is there any way to include the math.h header and somehow override the functions so that they can only be called from some implementation class? (basically I need to be able to use sin, cos, tan, etc. as variables and wanted to use a reader-friendly Math.sin() etc. for the math functions and GUI.sin() for the faster but less precise functions.
What do I do with the ftp link?
I am on a laptop, but I dont know where to get the latest version of mesa, also I dont think my headers and libraries are up to date since they are missing some functions that they should have, so I think I should upgrade them too. But how?
Should I try to see if I can update the version of OpenGL on my machine?
Same here...
My question was whether the library itself uses some special technique to do the calculations faster (asm on some special chip or something)
I forgot to mention that I am 90% sure that I am running OpenGL version 2.1 (I have asked my IT department before)
If I make my own math header with similar functions as math.h, can I possibly make it as fast as the implementations of math.h, or does math.h use special hardware or something?
I tried to use this to get my version, but nothing was printed:
#include <gl/gl.h>
#include <iostream>
using namespace std;
int main()
{
cout<<glGetString(GL_VERSION);
return 0;
}
Ok I have implemented your suggestions, except the Texture and Normal coordinates as I do not understand why they would be the same as the vertex coordinate. Also I think the problem with the NULL functions is the poor practice of using wglGetProcAddress. The issue is that I seem to be missing the OpenGL glext.h and its library, so I made my own (glext2.h) and since I am missing the library I cannot use the real functions. Is there anywhere that I can download the OpenGL headers and libraries?
Still getting the Errors with GOODGL enabled, and a clear screen without it. I have decided to put my entire 3dglgui.h in here so...
#ifndef LAB2DGLGUI_H
#ifndef CLASS_NAME
#define CLASS_NAME "OpenGL Windows Class"//This can be overwritten to specify a unique class name
#endif
//Header Guards and version number
#ifndef LAB3DGLGUI_H
#define LAB3DGLGUI_H 1.0
//Error codes
#define ERR_NO_ERROR 0x0000
#define ERR_CLASS_REGISTRY_FAILED 0x0001
#define ERR_FULLSCREEN_FAILED 0x0002
#define ERR_WINDOW_CREATION_FAILED 0x0004
#define ERR_GET_DC_FAILED 0x0008
#define ERR_PIXEL_FORMAT_CHOICE_FAILED 0x0010
#define ERR_NO_VALID_PIXEL_FORMAT 0x0020
#define ERR_GET_RC_FAILED 0x0040
#define ERR_MAKE_CURRENT_FAILED 0x0080
#define ERR_OPENGL_INITIALIZATION_FAILED 0x0100
#define ERR_RELEASE_DC_RC_FAILED 0x0200
#define ERR_RELEASE_RC_FAILED 0x0400
#define ERR_RELEASE_DC_FAILED 0x0800
#define ERR_RELEASE_WINDOW_FAILED 0x1000
#define ERR_RELEASE_WINDOW_CLASS_FAILED 0x2000
#define APART(X) ((float)((char)((X)>>24))/255.0)
#define RPART(X) ((float)((char)((X)>>16))/255.0)
#define GPART(X) ((float)((char)((X)>>8))/255.0)
#define BPART(X) ((float)((char)((X)))/255.0)
#define DEGTORAD(X) ((X)*0.0174532925)
//Includes
#include <math.h>//for trig ratios and sqrt
#include <windows.h>//for windows
#include <gl/gl.h>
#include <gl/glu.h>
#define GL_GLEXT_PROTOTYPES
#include <gl/glext2.h>
#include "models.h"
#include "random.h"
RND Rand;
//typedefs
typedef GLuint glTexture;//Storage for one (or more) textures
typedef unsigned int glColour;//Stores a colour as 0xAARRGGBB
//Unique main function
#define main() WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevhInstance, LPSTR cmdline, int cmdshow)
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
class glFont
{
private:
unsigned int letters;
GLYPHMETRICSFLOAT chars[256];
public:
void Load(const char *fname, int height, int weight, bool italic, bool underline, bool strikethrough, float depth);
void operator()(const char *str);
~glFont(){glDeleteLists(letters,255);}
};
class OpenGLInstance
{
private:
GLUquadricObj *quadricobject;
HDC hDC;
HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
LONGLONG tm;
public:
short ERRORCODE;
struct windowdatastructure
{
bool key[256]; bool active; bool fullscreen; int w; int h; int fps;
}window;
struct mousedatastructure
{
int x; int y; int scroll; …
Also when I comment out model.Draw() I get just a clear screen (not black)
You were right, all of the functions were NULL... unfortunately when I use #define GOODGL
then I get the following compiler errors:
D:\Programming\C++\glHeaders\models.h||In constructor 'glModel::glModel()':|
D:\Programming\C++\glHeaders\models.h|36|warning: 'glModel::vars' will be initialized after|
D:\Programming\C++\glHeaders\models.h|33|warning: 'int glModel::id'|
D:\Programming\C++\glHeaders\models.h|54|warning: when initialized here|
D:\Programming\C++\glHeaders\models.h||In member function 'glVertexStructure& glModel::operator[](int) const':|
D:\Programming\C++\glHeaders\models.h|76|warning: comparison between signed and unsigned integer expressions|
D:\Programming\C++\glHeaders\models.h|85|warning: comparison between signed and unsigned integer expressions|
D:\Programming\C++\glHeaders\models.h||In member function 'glModel& glModel::operator=(const glModel&)':|
D:\Programming\C++\glHeaders\models.h|116|warning: comparison between signed and unsigned integer expressions|
D:\Programming\C++\glHeaders\models.h||In member function 'glModel& glModel::operator+=(const glVertexStructure&)':|
D:\Programming\C++\glHeaders\models.h|161|warning: comparison between signed and unsigned integer expressions|
D:\Programming\C++\glHeaders\models.h||In member function 'glModel& glModel::Vertex(float, float, float, float, float)':|
D:\Programming\C++\glHeaders\models.h|212|warning: comparison between signed and unsigned integer expressions|
obj\Debug\test.o:D:\Programming\C++\glHeaders\models.h|259|undefined reference to `glGenBuffers@8'|
obj\Debug\test.o:D:\Programming\C++\glHeaders\models.h|260|undefined reference to `glBindBuffer@8'|
obj\Debug\test.o:D:\Programming\C++\glHeaders\models.h|261|undefined reference to `glBufferData@16'|
obj\Debug\test.o:D:\Programming\C++\glHeaders\models.h|282|undefined reference to `glBindBuffer@8'|
||=== Build finished: 4 errors, 8 warnings ===|
Maybe I need to install a newer version of OpenGL???
Thank you very much!
But when I swap wont I lose all of my 3D stuff?
Here is my main:
int main()
{
GL.Init("TEST",500,500,24,false,0,0);
glModel model;
model.Vertex(0,0,0,0,0);
model.Vertex(1,1,1,1,1);
model.Vertex(1,0,1,1,0);
model.Draw();
do{
GL.Update();
}while(!GL.window.key[VK_ESCAPE]);
return 0;
}
And here is gl.Init():
OpenGLInstance &OpenGLInstance::Init(const char *title, int width, int height, int bpp, bool fullscreen, int posx, int posy)
{
DEVMODE tmp;
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&tmp);
window.fps=tmp.dmDisplayFrequency;
unsigned int PixelFormat;
DWORD dwExStyle,dwStyle;
RECT WindowRect={(long)0,(long)0,(long)width,(long)height};
window.fullscreen=fullscreen;
hInstance=GetModuleHandle(NULL);
WNDCLASS wc={CS_HREDRAW|CS_VREDRAW|CS_OWNDC,(WNDPROC)WndProc,0,0,hInstance,LoadIcon(NULL,IDI_WINLOGO),LoadCursor(NULL,IDC_ARROW),NULL,NULL,CLASS_NAME};
(!RegisterClass(&wc))?ERRORCODE|=ERR_CLASS_REGISTRY_FAILED:ERRORCODE=ERRORCODE;
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth=width;
dmScreenSettings.dmPelsHeight=height;
dmScreenSettings.dmBitsPerPel=bpp;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSHEIGHT|DM_PELSWIDTH;
(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)?ERRORCODE|=ERR_FULLSCREEN_FAILED:ERRORCODE=ERRORCODE;
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
ShowCursor(false);
}
else
{
dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect,dwStyle,false,dwExStyle);
if (!(hWnd=CreateWindowEx(dwExStyle,CLASS_NAME,title,WS_CLIPSIBLINGS|WS_CLIPCHILDREN|dwStyle,posx,posy,WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,NULL,NULL,hInstance,NULL)))
{
Kill();
ERRORCODE|=ERR_WINDOW_CREATION_FAILED;
}
static PIXELFORMATDESCRIPTOR pfd={sizeof(PIXELFORMATDESCRIPTOR),1,PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,bpp,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE,0,0,0,0};
if (!(hDC=GetDC(hWnd)))
{
Kill();
ERRORCODE|=ERR_GET_DC_FAILED;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
Kill();
ERRORCODE|=ERR_PIXEL_FORMAT_CHOICE_FAILED;
}
if (!SetPixelFormat(hDC,PixelFormat,&pfd))
{
Kill();
ERRORCODE|=ERR_NO_VALID_PIXEL_FORMAT;
}
if (!wglMakeCurrent(hDC,hRC))
{
Kill();
ERRORCODE|=ERR_MAKE_CURRENT_FAILED;
}
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
Resize(width,height);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_COLOR_MATERIAL);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
quadricobject=gluNewQuadric();
gluQuadricNormals(quadricobject,GLU_SMOOTH);
gluQuadricTexture(quadricobject,GL_TRUE);
return *this;
}
Ok, I like the idea of just drawing stuff with minimal z order. Thanks!
I removed the leading declarations from genfunc() but it didnt help the sigseg. In fact it seems to have a negative impact, moving the sigseg back a line.
I am not entirely I understand the question either, but my guess is that your task is to write a function that can determine the length of stack a without actually using it. I think that you could make a copy of stack a as elements are added to it in stack b, then just write something to determine the size of stack b.
How do I do 2D opengl? I need to be able to put stuff up on the screen so that it is not rendered in three dimensions, and I need the 3d stuff to still be 3d behind it.
YAY!!! We moved up one line!!! Still not working though. Here is the updated code:
#ifdef LAB3DGLGUI_H
#ifndef GLMODELS_H
#define GLMODELS_H
#ifndef GOODGL
typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
#else
#include <gl/glext.h>
#endif
#include <stdio.h>
struct glVertexStructure
{
float vert[3];
float text[2];
float norm[3];
}NULLV;
/* Model File Format (.mdl)
4 bytes (int) -> numv
32*numv bytes (glVertexStructure)-> vars
-> 12 bytes (float[3]) -> vert
-> 8 bytes (float[2]) -> text
-> 12 bytes (float[3]) -> norm
*/
int HIGH_ID=0;
int COMPILED_ID=0;
class glModel
{
private:
int id;
unsigned int numv;
unsigned int model;
glVertexStructure *vars;
glModel &Compile();
PFNGLGENBUFFERSARBPROC glGenBuffersD;
PFNGLBINDBUFFERARBPROC glBindBufferD;
PFNGLBUFFERDATAARBPROC glBufferDataD;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersD;
void genfunc()
{
#ifndef GOODGL
PFNGLGENBUFFERSARBPROC glGenBuffersD=(PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
PFNGLBINDBUFFERARBPROC glBindBufferD=(PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
PFNGLBUFFERDATAARBPROC glBufferDataD=(PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersD=(PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
#endif
}
public:
glModel():numv(0),model(0),vars(0),id(++HIGH_ID){genfunc();}
glModel(const glModel&);
glModel(const char*);//Load from .mdl
~glModel()
{
if (numv>0)
delete[]vars;
//Clean up VBOs??? Research needed!
}
glModel &operator=(const glModel&);
glModel &operator=(const char*);//Load from .mdl
glModel operator+(const glVertexStructure&)const;//Add Vertices
glModel operator+(const glModel&)const;
glModel &operator+=(const glVertexStructure&);//Append Vertices
glModel &operator+=(const glModel&);
glModel &Load(const char*);//Load from .mdl
glModel &Save(const char*);//Save to .mdl
glModel &Vertex(float tx, float ty, float x, float y, float z);
glModel &Draw();
glModel &Move(float x, float y, float z){glTranslatef(x,y,z);return *this;}
int len()const{return numv;}
glVertexStructure &operator[](int x)const{if (x<numv){return vars[x];}else{return NULLV;}}
};
glModel::glModel(const glModel &source)
{
numv=source.len();
vars=new glVertexStructure[numv];
for (int i=0; …
Thank you, the missing line worked!
I just tested your code, it does not seem to work. TEST CASES:
TEST|EXPECTED|ACTUAL
~~~~~~~~~~~~~~~~~~~~
15 | 0| 1
63 | 0| 1
8 | 1| 0
I cant say I fully understand... the 0333333333 and 0111111111 are in what base?
Anyways, this sounds very clever!
I think I understand, take a look at the getch() function, http://en.wikipedia.org/wiki/Conio.h
If you dont want to do that you will have to use ints and use the modulo (%) operator to get each digit.
oh that is easy, change the chars into ints, they have a larger range.
I dont fully understand, is the issue that not all of the letters are being entered? or that the order is so close?
If what you want to do is use a loop to test the chars rather than a bunch of if statements then you will have to use an array.
Quick question (though I still want to get my long OpenGL question fixed) is there a faster way to Xor the bits of an integer than this:
(MyInt&0x1)^((MyInt&0x2)>>1)^((MyInt&0x4)>>2)//etcetera
Just to clarify by faster I mean faster to execute, not to type as this operation will have to be done many many times.
Oh, sorry I didnt tell you, that code still sigsegs in the Compile() function.
Ok, here is my updated code:
#ifdef LAB3DGLGUI_H
#ifndef GLMODELS_H
#define GLMODELS_H
#ifndef GOODGL
typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
PFNGLGENBUFFERSARBPROC glGenBuffersD=(PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
PFNGLBINDBUFFERARBPROC glBindBufferD=(PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
PFNGLBUFFERDATAARBPROC glBufferDataD=(PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersD=(PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
#else
#include <gl/glext.h>
#endif
#include <stdio.h>
struct glVertexStructure
{
float vert[3];
float text[2];
float norm[3];
}NULLV;
/* Model File Format (.mdl)
4 bytes (int) -> numv
32*numv bytes (glVertexStructure)-> vars
-> 12 bytes (float[3]) -> vert
-> 8 bytes (float[2]) -> text
-> 12 bytes (float[3]) -> norm
*/
int HIGH_ID=0;
int COMPILED_ID=0;
class glModel
{
private:
int id;
unsigned int numv;
unsigned int model;
glVertexStructure *vars;
glModel &Compile();
PFNGLGENBUFFERSARBPROC glGenBuffersD;
PFNGLBINDBUFFERARBPROC glBindBufferD;
PFNGLBUFFERDATAARBPROC glBufferDataD;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersD;
void genfunc()
{
#ifndef GOODGL
PFNGLGENBUFFERSARBPROC glGenBuffersD=(PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
PFNGLBINDBUFFERARBPROC glBindBufferD=(PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
PFNGLBUFFERDATAARBPROC glBufferDataD=(PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersD=(PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
#endif
}
public:
glModel():numv(0),model(0),vars(0),id(++HIGH_ID){genfunc();}
glModel(const glModel&);
glModel(const char*);//Load from .mdl
~glModel()
{
if (numv>0)
delete[]vars;
//Clean up VBOs??? Research needed!
}
glModel &operator=(const glModel&);
glModel &operator=(const char*);//Load from .mdl
glModel operator+(const glVertexStructure&)const;//Add Vertices
glModel operator+(const glModel&)const;
glModel &operator+=(const glVertexStructure&);//Append Vertices
glModel &operator+=(const glModel&);
glModel &Load(const char*);//Load from .mdl
glModel &Save(const char*);//Save to .mdl
glModel &Vertex(float tx, float ty, float x, float y, float z);
glModel &Draw();
glModel &Move(float x, float y, float z){glTranslatef(x,y,z);return *this;}
int len()const{return numv;}
glVertexStructure &operator[](int x)const{if (x<numv){return vars[x];}else{return NULLV;}}
};
glModel::glModel(const glModel &source)
{
numv=source.len();
vars=new glVertexStructure[numv];
for (int i=0; i<numv; …
Thank you. I will start implementing these changes now. Ill tell you if they work.