• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

theUnknowing

Textures from IplImage

1 post in this topic

I''m trying to create a dynamic texture for the purposes of displaying captured frames from a web-cam using OpenGL, instead of the premade functions of OpenCV. Moreover, if I can get this to work, I will be able to draw on the captured image using GL functions, which (as I understand it) should be much faster, and have many more options then using the OpenCV drawing primatives. One of the basic requirements of this program is that it NOT use GLUT in any way. It is required to be a "Win32 Application", and I am copiling/linking/running using MSVisual C++. The problem I am encountering is getting the data from the IplImage structure to become a texture. The texture I get output is pure white (I assume this, since the clear-color for the windw is black). I''m including incomplete code-snipets to show my efforts. Please note that my code is VERY dirty and unorganized at this point, but I will make it prettier when I get things to work. BEGINNING OF CODE-SNIPETS: //-------------------------------------------------------------- //My initializations; run at beginning of ''WinMain'' program. //-------------------------------------------------------------- /*Neccessary to show this line to show that the IplImage variable ''camTexture'' is pre-made to a size which conforms to the requirements for a texture... that its width and height are powers of 2 (shown here as 128x128). IPL_DEPTH_8U means that the image''s bit-depths are unsigned 8-bit integers. The final number is the number of channels in the image (from 1 - 4)*/ IplImage *camTexture = cvCreateImage(cvSize(128,128), IPL_DEPTH_8U, 3); glBindTexture(GL_TEXTURE_2D, 1); //I''m not clear on if this line is necessary, or even if I''m using it right. glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //GL Texture Parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //Can I get an explanation of this line as well? Documentaion is not good to get things in layman''s terms. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //GL Initializations, run just before my main message-processing loop. glShadeModel(GL_SMOOTH); //glClearDepth(1.0f); //glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glBindTexture(GL_TEXTURE_2D, 1); //-------------------------------------------------------------- //Everything from here on is in my Message-Processing loop for my open window; assume everything is simply run repeatedly. //-------------------------------------------------------------- //Setting textures for this drawing cycle. glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 1); /*OpenCV functions; I''ll explain each for clarity.*/ //Grabs a frame from the input camera and stores internally. cvGrabFrame( capture ); //Moves the internally stored image to an ''IplImage'' object. frame = cvRetrieveFrame( capture ); //Fills ''camTexture'' with data from ''frame'', formatted to EXACTLY fit into camTexture. cvResize(frame, camTexture); //Corrects x-axis flipping caused by copy from previous line. cvFlip(camTexture, NULL, 0); /*END of OpenCV functions*/ //For debugging. Insert "test1 = glGetError(); where needed. GLenum test1; glBindTexture(GL_TEXTURE_2D, 1); /* "camTexture->(width or height)" returns (int) indicating size of IplImage. "camTexture->imageDate" returns a pointer to a (char*), which (from the Ipl specs) is a "pointer to aligned image data".*/ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, camTexture->width, camTexture->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, camTexture->imageData); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); //Attempts to draw texture to the opened window. glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); //Diables texturing at the end of each loop. glDisable(GL_TEXTURE_2D); END OF CODE-SNIPETS. Sorry, I know that''s a lot to digest, and a lot of the potential problems don''t even have anything to do with OpenGL. But there are no forums out there (that I can find) called "Using OpenGL and OpenCV Together". One more thing before I post this and begin to wade hip-deep through the "That''s not an OpenGL question!!" flames; the ONLY source of potential problems I''ve been able to find with my own efforts: I took the "IplImage camText" object, and displayed it to my screen using CV functions. It looked fine, but to satisify my own curiosity, I begin lowering the size of the image from 128x128, to 64x64, all the way down to 2x2. At 2x2, I should see (so you would think), four pixels output. Instead, there is only one pixel, and it only takes up the lower-right of the display. Put another way, the first row and first column of the image are consistently NULL. I have no idea what could cause this, and I doubt it''s even the problem, but it''s the only lead I''ve been able to find. Anyways, if you need more detail, I''ll be happy to provide it. Any insights would be very appreciated at this point. Thanks, CP
0

Share this post


Link to post
Share on other sites
With my super light opencv library "[url="http://www.barbato.us/2010/10/14/image-data-structure-based-shared_ptr-iplimage/"]blImageAPI[/url]", you can easily do that with a couple of lines of code. Check it out, it also wraps IplImage with shared_ptr giving you automatic memory deallocation.
There's an example at the post [url="http://www.barbato.us/2010/11/11/load-an-iplimage-into-an-opengl-texture-and-create-webcam-and-video-textures-using-the-blimageapi/"]blTexture[/url] where I show how I connect to the webcam and feed the video into an opengl texture.

There's also the ability to do that in a parallel thread so that the main opengl thread is not slowed down by the video grabbing thread.

Enjoy,
Enzo





0

Share this post


Link to post
Share on other sites