PDA

View Full Version : can we use opengl to create *.dll and *.lib file?



apit
08-11-2003, 08:33 AM
i have create a program to split window to two view using glut.. now i want to make the program as a library(.dll and .lib)... can i do that? this is my code::

////////////////////////////////////////////
#include <gl\glut.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <math.h>
#include <stdlib.h>
#include "split.h"


void changeSize(int w1, int h1)
{

// elakkan devide by zero
ratio = 1.0f * w1 / h1;

// Reset koordinat gl_projection sebelum diubahsuai
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set viewport kpd keseluruhan window
glViewport(0, 0, w1, h1); //(0,0)=specifies lower-left coner of the viewport

// Set the clipping volume
gluPerspective(45,ratio,0.1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


}

void SeparateWindow(int w1,int h1)
{
if(h1 == 0)
h1 = 1;

w = w1;
h = h1;

//Separate Window Sebelah Kiri
glutSetWindow(subWindowKiri);
glutPositionWindow(border,border);
glutReshapeWindow(w/2-border*3/2,h-2*border);//w-2*border, h/2 - border*3/2);-devide atas bawah
changeSize(w/2-border*3/2,h-2*border);//w-2*border, h/2 - border*3/2);-devide atas bawah

//Separate Window Sebelah Kanan
glutSetWindow(subWindowKanan);
glutPositionWindow((w+border)/2,border);
glutReshapeWindow(w/2-border*3/2,h-2*border);//w-2*border, h/2 - border*3/2);
changeSize(w/2-border*3/2,h-2*border);//w-2*border,h/2 - border*3/2);

}


void DrawTriangle(int x)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();

//glRotatef(angle,0.0,1.0,0.0);
glColor3f(0.0,0.0,1.0);
//glScalef(10.0,0.0,0.0);
//glTranslatef(0.0f, 0.0f, -2.0f);
//draw triangle
glBegin(GL_TRIANGLES);
glVertex3f(-2.0,1.0,0.0);
glVertex3f(3.0,1.0,0.0);
glVertex3f(0.0,3.0,0.0);
glEnd();


glPopMatrix();
angle++;

glutSwapBuffers();
}

void renderScene()
{
glutSetWindow(mainWindow);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}

void renderSceneKiri()
{
glutSetWindow(subWindowKiri);
glLoadIdentity();
gluLookAt(x, y, z,
0.11285,y+ly,0.222,//x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);


DrawTriangle(subWindowKiri);
}

void renderSceneKanan()
{
glutSetWindow(subWindowKanan);
glLoadIdentity();

gluLookAt(x, y, z, //lokasi kamera - nilai (0,0,0)= asalan
-0.11285,y+ly,0.222,//x + lx,y + ly,z + lz, //dimana camera halakan/point = line of sight
0.0f,1.0f,0.0f); //vektor yg menerangkan arah atas
DrawTriangle(subWindowKanan);
}

void renderSceneAll()
{

renderSceneKiri();
renderSceneKanan();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(w,h);
mainWindow = glutCreateWindow("Two View");
glutReshapeFunc(SeparateWindow);
glutDisplayFunc(renderScene);
glutIdleFunc(renderSceneAll);

//Separate Window Sebelah Kiri
//identifier |window |window |width in |height
//sub window |x location |y location |pixel |in pixel
subWindowKiri = glutCreateSubWindow(mainWindow, border ,border ,w/2-border*3/2,h-2*border);//w-2*border, h/2 - border*3/2);
glutDisplayFunc(renderSceneKiri);

//Separate Window Sebelah Kanan
subWindowKanan = glutCreateSubWindow(mainWindow, (w+border)/2,border,w/2-border*3/2,h-2*border);//w-2*border, h/2 - border*3/2);
glutDisplayFunc(renderSceneKanan);
glutMainLoop();

return(0);
}
////////////////////////////////////////////

Gavin
08-11-2003, 02:43 PM
whats your api?

apit
08-11-2003, 10:39 PM
sorry...i don't really understand your question... what do you mean by api? i'm using glut as a library.. mvcpp as editor..

Sourpotato
08-11-2003, 11:33 PM
First i am not sure you can use glut to generate lib/dll,more likely you can't.
you have to select "Win32 Dynamic-Link Library" when you create a new project in vc6.
then in your program
the dll entry point is dllMain unlike common entry point which is winmain.

And your global function will be callbacked.so you should export functions
like this EXPORT VOID CALLBACK yourfunction()

<Windows Programming> has one chapter deal with how to make a dll/lib. look it up yourselves when necessary.


[This message has been edited by RunningRabbit (edited 08-12-2003).]

apit
08-12-2003, 08:59 PM
so that mean i cannot use glut to generate *.dll and *.lib file? do you have any idea to separate two view and make it as a library?

Sourpotato
08-12-2003, 09:59 PM
yes,you got my point. But i can not understand why you have to put the split window into another libary. this is not way of doing.Usually we use child window or glScssior to split window. and these split window codes is un-seperated part of the whole GL application.Maybe i am arbitary a bit,correct me if i am wrong.

Deiussum
08-13-2003, 05:28 AM
Yes, you can put stuff into a library. Glut won't generate a library for you, though. You have to generate the library with your compiler. How you do this, and what you put in the library is up to you. It all depends on what exactly you want, which is pretty vague in your post.

apit
08-15-2003, 08:25 PM
i got your point guys..
thanks a lot..
so i don't have to split the two view coding with the main code... just combain it together..

question 2
--------------
maybe this not related with this topic but it is very nice if you all can help me..
how can i make my program in stereoview..
i have split the screen and the program running well both ringht anf left view.. the problem now is to make it look stereoviewing.. how can i do that..
can i just modify the gluLookat value to make it stereoview.. or i should calculate the stereo ?

zeckensack
08-16-2003, 03:47 PM
Your eyes should be a couple of inches or so apart from each other (I assume).
If you know what 'a couple of inches' is in your world coords, you can seperate the viewpoints of your stereo views by this amount. Or better yet, make it configurable and play around with it until it starts looking convincing http://www.opengl.org/discussion_boards/ubb/smile.gif

noselasd
08-18-2003, 12:45 AM
Originally posted by apit:
[B]i have create a program to split window to two view using glut.. now i want to make the program as a library(.dll and .lib)... can i do that? this is my code::



Yes you can. But it has nothing to do with OpenGL or GLUT. Read docs for your OS/Compiler(Visual C++ I assume) on how to create DLL/LIB's

Sourpotato
08-18-2003, 08:22 PM
stereoview:

hmmm,I have read through it in gl scissor chapters of the redbook.But i never found any articles/sample ever give a **** on this part of opengl.I even suspect if there is any implementation of this stereoview on graphic cards.Sorry, i can not be of further help.

apit
08-19-2003, 08:19 AM
so that mean i should use windows programming if i want to make a split screen library?

Deiussum
08-19-2003, 09:13 AM
I think it means that you need to spend some more time learning general programming concepts if you want to write part of your code in a library. You obviously didn't understand what was said about making a library being a compiler-specific thing.